Example #1
0
func newUserRecovery(userId int64) (ur *UserRecovery) {
	ur = &UserRecovery{}
	ur.UserId = userId
	ur.Active = true
	ur.CreateTime = time.Now().UTC()

	token, _ := utils.GenerateRandomString(20)
	ur.Token = token
	return
}
Example #2
0
func ThirdParty_CreateAndBind(email string, name string, profile *ThirdPartyUserProfile) (u *ThirdPartyUser, err error) {
	if len(email) == 0 {
		err = NewThirdPartyBindError("邮箱不能为空")
		return
	}
	if len(name) == 0 {
		err = NewThirdPartyBindError("昵称不能为空")
		return
	}

	if User_IsEmailExist(email) {
		err = NewThirdPartyBindError("邮箱已经被注册过了,使用登录并绑定吧~~~")
		return
	}
	if User_IsUserExist(name) {
		err = NewThirdPartyBindError("哎呀,昵称已经被占用了哟,换一个试一下吧~~~")
		return
	}

	pwd, _ := utils.GenerateRandomString(5)
	pwdHash := utils.PasswordHash(pwd)

	//TODO: send notification email
	m := make(map[string]interface{})
	m["name"] = name
	m["email"] = email
	m["pwd"] = pwdHash
	m["create_time"] = time.Now()
	_, err = User_SaveMap(m)

	if err != nil {
		return
	}

	user, err := User_GetByEmail(email)
	u, err = ThirdParty_BindExistedUser(user, profile)

	return
}