本文整理匯總了Golang中pixelrelay/db.Dbh.InsertUser方法的典型用法代碼示例。如果您正苦於以下問題:Golang Dbh.InsertUser方法的具體用法?Golang Dbh.InsertUser怎麽用?Golang Dbh.InsertUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pixelrelay/db.Dbh
的用法示例。
在下文中一共展示了Dbh.InsertUser方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetupAdminPost
func SetupAdminPost(sa forms.SetupAdmin, args martini.Params, session sessions.Session, r render.Render, res http.ResponseWriter, dbh *db.Dbh) {
errs := Validate(&sa)
if len(errs) > 0 {
fmt.Printf("%+v\n", errs)
}
v := session.Get("setup")
if v != "true" {
http.Error(res, "Unauthorized", http.StatusUnauthorized)
return
}
user := dbh.GetUserByEmail(sa.Email)
if user.Id > 0 {
fmt.Println("user already exists")
session.Set("uid", user.Id)
}
if user.Id == 0 {
fmt.Println("id: 0")
hash, salt, err := auth.EncryptPassword(sa.Password)
if err != nil {
fmt.Println("hash err: ", err)
}
newuser := models.User{Name: sa.Name, Email: sa.Email, Password: hash, Salt: salt, Timestamp: time.Now().Unix()}
dbh.InsertUser(newuser)
session.Set("uid", newuser.Id)
}
uid := session.Get("uid")
fmt.Println("uid: ", uid)
genform := utils.GenerateForm(&sa, "/setup", "POST", errs)
r.HTML(200, "setup", genform)
}