Beispiel #1
0
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()
}
Beispiel #2
0
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
}
Beispiel #3
0
func UserIsExists(username, email string) bool {
	user := models.User{}
	user.UserName = strings.ToLower(username)
	user.Email = strings.ToLower(email)
	return user.Exists()
}