mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
fix: handle aliyun captcha error (#1624)
This commit is contained in:
parent
fea2a8cdbe
commit
16b1d0e1f0
@ -31,6 +31,16 @@ import (
|
|||||||
|
|
||||||
const AliyunCaptchaVerifyUrl = "http://afs.aliyuncs.com"
|
const AliyunCaptchaVerifyUrl = "http://afs.aliyuncs.com"
|
||||||
|
|
||||||
|
type captchaSuccessResponse struct {
|
||||||
|
Code int `json:"Code"`
|
||||||
|
Msg string `json:"Msg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type captchaFailResponse struct {
|
||||||
|
Code string `json:"Code"`
|
||||||
|
Message string `json:"Message"`
|
||||||
|
}
|
||||||
|
|
||||||
type AliyunCaptchaProvider struct{}
|
type AliyunCaptchaProvider struct{}
|
||||||
|
|
||||||
func NewAliyunCaptchaProvider() *AliyunCaptchaProvider {
|
func NewAliyunCaptchaProvider() *AliyunCaptchaProvider {
|
||||||
@ -85,19 +95,20 @@ func (captcha *AliyunCaptchaProvider) VerifyCaptcha(token, clientSecret string)
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type captchaResponse struct {
|
return handleCaptchaResponse(body)
|
||||||
Code int `json:"Code"`
|
|
||||||
Msg string `json:"Msg"`
|
|
||||||
}
|
}
|
||||||
captchaResp := &captchaResponse{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(body, captchaResp)
|
func handleCaptchaResponse(body []byte) (bool, error) {
|
||||||
|
captchaResp := &captchaSuccessResponse{}
|
||||||
|
err := json.Unmarshal(body, captchaResp)
|
||||||
|
if err != nil {
|
||||||
|
captchaFailResp := &captchaFailResponse{}
|
||||||
|
err = json.Unmarshal(body, captchaFailResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if captchaResp.Code != 100 {
|
return false, errors.New(captchaFailResp.Message)
|
||||||
return false, errors.New(captchaResp.Msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user