本文整理汇总了Golang中github.com/varding/wetalk/modules/models.User.UserName方法的典型用法代码示例。如果您正苦于以下问题:Golang User.UserName方法的具体用法?Golang User.UserName怎么用?Golang User.UserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/varding/wetalk/modules/models.User
的用法示例。
在下文中一共展示了User.UserName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RegisterUser
// register create user
func RegisterUser(user *models.User, username, email, password string, locale i18n.Locale) error {
// use random salt encode password
salt := models.GetUserSalt()
pwd := utils.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 = utils.EncodeMd5(user.Email)
// Use username as default nickname.
user.NickName = user.UserName
//set default language
if locale.Lang == "en-US" {
user.Lang = setting.LangEnUS
} else {
user.Lang = setting.LangZhCN
}
//set default avatar
user.AvatarType = setting.AvatarTypeGravatar
return user.Insert()
}
示例2: LoginUserFromRememberCookie
func LoginUserFromRememberCookie(user *models.User, ctx *context.Context) (success bool) {
userName := ctx.GetCookie(setting.CookieUserName)
if len(userName) == 0 {
return false
}
defer func() {
if !success {
DeleteRememberCookie(ctx)
}
}()
user.UserName = userName
if err := user.Read("UserName"); err != nil {
return false
}
secret := utils.EncodeMd5(user.Rands + user.Password)
value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName)
if value != userName {
return false
}
LoginUser(user, ctx, true)
return true
}
示例3: HasUser
// check if exist user by username or email
func HasUser(user *models.User, username string) bool {
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 {
return true
}
return false
}
示例4: getVerifyUser
// get user by erify code
func getVerifyUser(user *models.User, code string) bool {
if len(code) <= utils.TimeLimitCodeLength {
return false
}
// use tail hex username query user
hexStr := code[utils.TimeLimitCodeLength:]
if b, err := hex.DecodeString(hexStr); err == nil {
user.UserName = string(b)
if user.Read("UserName") == nil {
return true
}
}
return false
}
示例5: getUser
func (this *UserRouter) getUser(user *models.User) bool {
username := this.GetString(":username")
user.UserName = username
err := user.Read("UserName")
if err != nil {
this.Abort("404")
return true
}
IsFollowed := false
if this.IsLogin {
if this.User.Id != user.Id {
IsFollowed = this.User.FollowingUsers().Filter("FollowUser", user.Id).Exist()
}
}
this.Data["TheUser"] = &user
this.Data["IsFollowed"] = IsFollowed
return false
}