diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index 0b39e57e0..cd83b0da1 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -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 } diff --git a/business/model/auth2.go b/business/model/auth2.go index da9257fbd..f46437d7d 100644 --- a/business/model/auth2.go +++ b/business/model/auth2.go @@ -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:"-"` } diff --git a/controllers/auth2.go b/controllers/auth2.go index 940cf76e2..51754e89f 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -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 }) }