本文整理汇总了Golang中gitlab.com/thanzen/identity/models/user.User.PasswordSalt方法的典型用法代码示例。如果您正苦于以下问题:Golang User.PasswordSalt方法的具体用法?Golang User.PasswordSalt怎么用?Golang User.PasswordSalt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gitlab.com/thanzen/identity/models/user.User
的用法示例。
在下文中一共展示了User.PasswordSalt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SaveNewPassword
// set a new password to user
func (this *UserService) SaveNewPassword(u *user.User, password string) error {
salt := GetUserSalt()
u.Password = fmt.Sprintf("%s$%s", salt, utils.EncodePassword(password, salt))
u.PasswordSalt = salt
_, err := orm.NewOrm().Update(u, "Password", "PasswordSalt", "Updated")
return err
}
示例2: Active
// Active implemented check Email actice code.
func (this *RegisterController) Active() {
this.TplName = "auth/active.html"
// no need active
if this.CheckActiveRedirect(false) {
return
}
code := this.GetString(":code")
var user user.User
if this.UserService.VerifyUserActiveCode(&user, code) {
user.Active = true
user.PasswordSalt = userServ.GetUserSalt()
if err := this.UserService.Update(&user, "Active", "PasswordSalt", "Updated"); err != nil {
beego.Error("Active: user Update ", err)
}
if this.IsLogin {
this.User = user
}
this.Redirect("/active/success", 302)
} else {
this.Data["Success"] = false
}
}
示例3: RegisterUser
// register a user
func (this *UserService) RegisterUser(u *user.User, username, email, password string, userType *user.UserType, role *user.Role) error {
u.UserType = userType
// use random salt encode password
salt := GetUserSalt()
pwd := utils.EncodePassword(password, salt)
u.Username = strings.ToLower(username)
u.Email = strings.ToLower(email)
// save salt and encode password, use $ as split char
u.Password = fmt.Sprintf("%s$%s", salt, pwd)
u.PasswordSalt = salt
var err error
tr := orm.NewOrm()
tr.Begin()
if err = this.InsertWithScope(tr, u); err == nil {
roleService := RoleService{}
err = roleService.InsertUsersWithScope(tr, role, u)
}
if err == nil {
tr.Commit()
} else {
tr.Rollback()
}
return err
}
示例4: ResetPost
// Reset implemented user password reset.
func (this *ForgotController) ResetPost() {
this.TplName = "auth/reset.html"
code := this.GetString(":code")
this.Data["Code"] = code
var user user.User
if this.UserService.VerifyUserResetPwdCode(&user, code) {
this.Data["Success"] = true
form := ResetPwdModel{}
if this.ValidFormSets(&form) == false {
return
}
user.Active = true
user.PasswordSalt = userServ.GetUserSalt()
if err := this.UserService.SaveNewPassword(&user, form.Password); err != nil {
beego.Error("ResetPost Save New Password: ", err)
}
if this.IsLogin {
this.LogoutUser(this.Ctx)
}
this.FlashRedirect("/login", 302, "ResetSuccess")
} else {
this.Data["Success"] = false
}
}
示例5: InsertWithScope
func (this UserService) InsertWithScope(tr orm.Ormer, u *user.User) error {
u.PasswordSalt = GetUserSalt()
if !utils.IsEmail(u.Email) {
return errors.New("invalid email")
}
beego.Info(setting.SystemAdminEmails)
if strings.Index(setting.SystemAdminEmails, u.Email) >= 0 {
u.IsSystemAccount = true
beego.Info(setting.SystemAdminEmails)
}
if _, err := tr.Insert(u); err != nil {
return err
}
return nil
}