diff options
Diffstat (limited to 'routers/user/auth_openid.go')
-rw-r--r-- | routers/user/auth_openid.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/routers/user/auth_openid.go b/routers/user/auth_openid.go index ba2c8be8c2..39e75f202d 100644 --- a/routers/user/auth_openid.go +++ b/routers/user/auth_openid.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/generate" + "code.gitea.io/gitea/modules/hcaptcha" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/recaptcha" "code.gitea.io/gitea/modules/setting" @@ -330,6 +331,7 @@ func RegisterOpenID(ctx *context.Context) { ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha ctx.Data["CaptchaType"] = setting.Service.CaptchaType ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey + ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL ctx.Data["OpenID"] = oid userName, _ := ctx.Session.Get("openid_determined_username").(string) @@ -359,24 +361,34 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL ctx.Data["CaptchaType"] = setting.Service.CaptchaType ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey + ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey ctx.Data["OpenID"] = oid if setting.Service.EnableCaptcha { var valid bool + var err error switch setting.Service.CaptchaType { case setting.ImageCaptcha: valid = cpt.VerifyReq(ctx.Req) case setting.ReCaptcha: - err := ctx.Req.ParseForm() - if err != nil { + if err := ctx.Req.ParseForm(); err != nil { ctx.ServerError("", err) return } - valid, _ = recaptcha.Verify(form.GRecaptchaResponse) + valid, err = recaptcha.Verify(ctx.Req.Context(), form.GRecaptchaResponse) + case setting.HCaptcha: + if err := ctx.Req.ParseForm(); err != nil { + ctx.ServerError("", err) + return + } + valid, err = hcaptcha.Verify(ctx.Req.Context(), form.HcaptchaResponse) default: ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType)) return } + if err != nil { + log.Debug("%s", err.Error()) + } if !valid { ctx.Data["Err_Captcha"] = true |