Esempio n. 1
0
// NewUser saves 'User' into database.
func NewUser(u *User) error {
	u.Rands = utils.GetRandomString(10)
	_, err := orm.NewOrm().Insert(u)
	if err != nil {
		return err
	}
	return nil
}
Esempio n. 2
0
// register create user
func RegisterUser(form RegisterForm, user *User) error {
	// use random salt encode password
	salt := utils.GetRandomString(10)
	pwd := utils.EncodePassword(form.Password, salt)

	user.UserName = form.UserName
	user.Email = form.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(form.Email)

	return NewUser(user)
}