当前位置: 首页>>代码示例>>Golang>>正文


Golang User.PasswordSalt方法代码示例

本文整理汇总了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
}
开发者ID:thanzen,项目名称:identity,代码行数:8,代码来源:userservice.go

示例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
	}
}
开发者ID:thanzen,项目名称:identity,代码行数:28,代码来源:register.go

示例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
}
开发者ID:thanzen,项目名称:identity,代码行数:28,代码来源:userservice.go

示例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
	}
}
开发者ID:thanzen,项目名称:identity,代码行数:34,代码来源:forgot.go

示例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
}
开发者ID:thanzen,项目名称:identity,代码行数:18,代码来源:userservice.go


注:本文中的gitlab.com/thanzen/identity/models/user.User.PasswordSalt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。