- SendVerifyCode add params authToken

This commit is contained in:
gazebo
2019-03-04 11:31:02 +08:00
parent 538a801ccd
commit b57e698df8
3 changed files with 21 additions and 11 deletions

View File

@@ -138,16 +138,25 @@ func CreateCaptcha(width, height, captchaLen int) (captchaInfo *CaptchaInfo, err
return captchaInfo, err
}
func SendVerifyCode(captchaID, captchaValue, authID string) (err error) {
if TestCaptchaMap[captchaID] == captchaValue || captcha.VerifyString(captchaID, captchaValue) {
func SendVerifyCode(authToken, captchaID, captchaValue, authID string) (err error) {
if authToken != "" {
_, err = GetTokenInfo(authToken)
} else if captchaID != "" && captchaValue != "" {
if !(TestCaptchaMap[captchaID] == captchaValue || captcha.VerifyString(captchaID, captchaValue)) {
err = ErrCaptchaIsNotOk
}
} else {
err = errors.New("发送验证必须要有认证或CAPTCHA信息")
}
if err == nil {
authType := GuessAuthTypeFromAuthID(authID)
if handler := authers[authType]; handler == nil {
return ErrIllegalAuthType
err = ErrIllegalAuthType
} else {
return handler.SendVerifyCode(authID)
err = handler.SendVerifyCode(authID)
}
}
return ErrCaptchaIsNotOk
return err
}
// 账号密码时authIDType可能是UserIDID,UserIDID2,UserIDMobile,UserIDEmailauthSecret是密码的sha1
@@ -293,7 +302,7 @@ func createToken(user IUser) (token string, tokenType int) {
TokenVer,
time.Now().Format("20060102-150405"),
userID,
userID,
utils.GetUUID(),
}, TokenTypeSep), tokenType
}

View File

@@ -17,7 +17,7 @@ type AuthBind struct {
AuthSecret string `orm:"size(48)" json:"authSecret"`
AuthSecret2 string `orm:"size(48)" json:"authSecret2"`
Remark string `orm:"size(255)" json:"remark"`
DetailData string `orm:"type(text)" json:"-"`
DetailData string `orm:"type(text)" json:"detailData"`
UserData interface{} `orm:"-" json:"-"`
}

View File

@@ -39,16 +39,17 @@ func (c *Auth2Controller) CreateCaptcha() {
}
// @Title 发送验证码
// @Description 发送验证码
// @Param captchaID formData string true "图片验证码ID"
// @Param captchaValue formData string true "图片验证码值"
// @Description 发送验证码图片验证码与authToken二者必须至少有一个
// @Param captchaID formData string false "图片验证码ID"
// @Param captchaValue formData string false "图片验证码值"
// @Param authToken formData string false "之前的认证信息"
// @Param authID formData string true "手机号或邮件"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SendVerifyCode [post]
func (c *Auth2Controller) SendVerifyCode() {
c.callSendVerifyCode(func(params *tAuth2SendVerifyCodeParams) (retVal interface{}, errCode string, err error) {
err = auth2.SendVerifyCode(params.CaptchaID, params.CaptchaValue, params.AuthID)
err = auth2.SendVerifyCode(params.AuthToken, params.CaptchaID, params.CaptchaValue, params.AuthID)
return retVal, "", err
})
}