- SendVerifyCode add params authToken
This commit is contained in:
@@ -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,UserIDEmail,authSecret是密码的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
|
||||
}
|
||||
|
||||
|
||||
@@ -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:"-"`
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user