Example #1
0
func CreateVerification(phone string) int {
	o := orm.NewOrm()
	code := utils.GenVerifyCode()
	// TODO send verify code
	verification := Verification{Phone: phone}
	_, _, err := o.ReadOrCreate(&verification, "Phone")
	if err != nil {
		beego.Warning("CreateVerification, ReadOrCreate fail: ", err)
		return utils.ERROR_CODE_SYSTEM_ERROR
	}

	verification.Code = code
	verification.Expire = time.Now().Unix() + utils.VERIFY_CODE_EXPIRE_IN_SECONDS
	_, err = o.Update(&verification)
	if err != nil {
		beego.Warning("CreateVerification, Update fail: ", err)
		return utils.ERROR_CODE_SYSTEM_ERROR
	}
	return 0
}
Example #2
0
func TestGenVerifyCode(t *testing.T) {
	code := utils.GenVerifyCode()

	assert.True(t, len(code) == utils.VERIFY_CODE_LEN)
}