本文整理匯總了Golang中github.com/EPICPaaS/account/models.User類的典型用法代碼示例。如果您正苦於以下問題:Golang User類的具體用法?Golang User怎麽用?Golang User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了User類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConnectPost
func (this *SocialAuthController) ConnectPost() {
token := this.Ctx.GetCookie("epic_user_token")
ok, userId := tools.VerifyToken(token)
if !ok || len(userId) == 0 {
this.Redirect("/", 302)
return
}
password := this.GetString("Password")
userName := this.GetString("UserName")
if len(userId) == 0 || len(password) == 0 || len(userName) == 0 {
this.Data["userId"] = userId
this.TplNames = "connect.html"
this.Data["error"] = "[用戶名]或者[密碼]為空"
this.Data["state"] = "注冊失敗"
this.Data["msg"] = "[用戶名]或者[郵箱]已被注冊"
return
}
isExist := auth.UserIsExists(userName, userName)
if isExist {
this.Data["userId"] = userId
this.TplNames = "connect.html"
this.Data["error"] = "[用戶名]或者[郵箱]已被注冊"
this.Data["state"] = "注冊失敗"
this.Data["msg"] = "[用戶名]或者[郵箱]已被注冊"
return
}
user := models.User{}
user.Password = password
user.UserName = userName
user.Id, _ = strconv.Atoi(userId)
err := auth.ConnectUpdateUser(&user, password)
if err != nil {
this.Data["userId"] = userId
this.TplNames = "connect.html"
this.Data["error"] = err.Error()
this.Data["state"] = "注冊失敗"
beego.Error("注冊失敗-插入數據庫出錯", err)
this.Data["msg"] = err.Error()
return
}
subSitesConf := config.GetSubSites()
this.Data["srcs"] = strings.Split(subSitesConf, ",")
this.Data["token"] = token
this.Data["state"] = "注冊成功"
this.Data["msg"] = "3秒後自動跳轉!!"
this.Data["succ"] = true
this.Data["redirectURL"] = config.GetRedirectURL()
this.TplNames = "succeed.html"
}
示例2: VerifyUser
func VerifyUser(username, password string) (bool, *models.User) {
isExists := UserIsExists(username, username)
user := models.User{}
if !isExists {
return false, &user
}
var err error
qs := orm.NewOrm()
if strings.IndexRune(username, '@') == -1 {
user.UserName = username
err = qs.Read(&user, "UserName")
} else {
user.Email = username
err = qs.Read(&user, "Email")
}
if err != nil {
fmt.Println("用戶登錄讀取用戶信息失敗" + err.Error())
return false, &user
}
ok := VerifyPassword(password, user.Password)
return ok, &user
}
示例3: RegisterUser
func RegisterUser(user *models.User, username, email, password string) error {
// use random salt encode password
salt := models.GetUserSalt()
pwd := tools.EncodePassword(password, salt)
user.UserName = strings.ToLower(username)
user.Email = strings.ToLower(email)
// save salt and encode password, use $ as split char
user.Password = fmt.Sprintf("%s$%s", salt, pwd)
// save md5 email value for gravatar
user.GrEmail = tools.EncodeMd5(user.Email)
// Use username as default nickname.
user.NickName = user.UserName
//設置用戶默認激活
user.IsActive = true
return user.Insert()
}
示例4: InitConnect
func InitConnect(identify string) (string, bool) {
user := models.User{}
user.Identify = identify
err := user.Read("Identify")
if err != nil {
err = user.Insert()
if err != nil {
fmt.Println("connect創建用戶失敗-" + err.Error())
}
}
id := user.Id
password := user.Password
if len(password) == 0 {
return strconv.Itoa(id), false
} else {
return strconv.Itoa(id), true
}
}
示例5: UserIsExists
func UserIsExists(username, email string) bool {
user := models.User{}
user.UserName = strings.ToLower(username)
user.Email = strings.ToLower(email)
return user.Exists()
}
示例6: ConnectUpdateUser
func ConnectUpdateUser(user *models.User, password string) error {
salt := models.GetUserSalt()
pwd := tools.EncodePassword(password, salt)
user.Password = fmt.Sprintf("%s$%s", salt, pwd)
return user.Update("UserName", "Password")
}
示例7: SaveNewPassword
func SaveNewPassword(user *models.User, password string) error {
salt := models.GetUserSalt()
user.Password = fmt.Sprintf("%s$%s", salt, tools.EncodePassword(password, salt))
return user.Update("Password", "Rands", "Updated")
}