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 InitConnect(identify string) (string, bool) {
	user := models.User{}
	user.Identify = identify
	err := user.Read("Identify")
	if err != nil {
		err = user.Insert()
		if err != nil {
			fmt.Println("connect创建用户失败-" + err.Error())
		}
	}
	id := user.Id
	password := user.Password
	if len(password) == 0 {
		return strconv.Itoa(id), false
	} else {
		return strconv.Itoa(id), true
	}

}