Пример #1
0
func UserPhoneExists(phone *string) bool {
	utils.AssertNotEmptyString(phone)
	o := orm.NewOrm()
	user := User{Phone: phone}
	err := o.Read(&user, "Phone")
	return err == nil
}
Пример #2
0
func VerifyUserByPhone(phone *string, secret string) (*User, int) {
	utils.AssertNotEmptyString(phone)
	o := orm.NewOrm()
	user := User{Phone: phone}
	err := o.Read(&user, "Phone")

	if err != nil {
		return nil, utils.ERROR_CODE_USERS_USER_NOT_EXISTS
	}

	if utils.Secret2Password("phone:"+*phone, secret) != user.Password {
		return nil, utils.ERROR_CODE_TOKENS_PASSWORD_MISMATCH
	}

	for i := 0; i < DB_UNIQUE_CONFLICT_TRY; i++ {
		user.Token = utils.GenToken()
		user.UpdateAt = utils.GetTimeMillis()
		_, err = o.Update(&user)
		if err == nil {
			return &user, 0
		}
		time.Sleep(1 * time.Millisecond)
	}

	beego.Warning("VerifyUser, update token fail: ", err)
	return nil, utils.ERROR_CODE_SYSTEM_ERROR
}
Пример #3
0
func getUserByQQInternal(o *orm.Ormer, openid *string) *User {
	utils.AssertNotEmptyString(openid)
	user := User{QQ: openid}
	err := (*o).Read(&user, "QQ")
	if err == nil {
		return &user
	}
	return nil
}
Пример #4
0
func CreateUserByPhone(phone *string, secret string) (*User, int) {
	utils.AssertNotEmptyString(phone)
	o := orm.NewOrm()
	password := utils.Secret2Password("phone:"+*phone, secret)
	user := User{Phone: phone, Password: password}

	var err error
	for i := 0; i < DB_UNIQUE_CONFLICT_TRY; i++ {
		user.Uid = utils.GenUid()
		user.Token = utils.GenToken()
		now := utils.GetTimeMillis()
		user.CreateAt = now
		user.UpdateAt = now
		_, err = o.Insert(&user)
		if err == nil {
			return &user, 0
		}
		time.Sleep(1 * time.Millisecond)
	}

	beego.Warning("CreateUser fail: ", err)
	return nil, utils.ERROR_CODE_SYSTEM_ERROR
}