@@ -17,11 +17,8 @@ import (
17
17
"code.gitea.io/gitea/modules/base"
18
18
"code.gitea.io/gitea/modules/context"
19
19
"code.gitea.io/gitea/modules/eventsource"
20
- "code.gitea.io/gitea/modules/hcaptcha"
21
20
"code.gitea.io/gitea/modules/log"
22
- "code.gitea.io/gitea/modules/mcaptcha"
23
21
"code.gitea.io/gitea/modules/password"
24
- "code.gitea.io/gitea/modules/recaptcha"
25
22
"code.gitea.io/gitea/modules/session"
26
23
"code.gitea.io/gitea/modules/setting"
27
24
"code.gitea.io/gitea/modules/timeutil"
@@ -163,6 +160,10 @@ func SignIn(ctx *context.Context) {
163
160
ctx .Data ["PageIsLogin" ] = true
164
161
ctx .Data ["EnableSSPI" ] = auth .IsSSPIEnabled ()
165
162
163
+ if setting .Service .EnableCaptcha && setting .Service .RequireCaptchaForLogin {
164
+ context .SetCaptchaData (ctx )
165
+ }
166
+
166
167
ctx .HTML (http .StatusOK , tplSignIn )
167
168
}
168
169
@@ -189,6 +190,16 @@ func SignInPost(ctx *context.Context) {
189
190
}
190
191
191
192
form := web .GetForm (ctx ).(* forms.SignInForm )
193
+
194
+ if setting .Service .EnableCaptcha && setting .Service .RequireCaptchaForLogin {
195
+ context .SetCaptchaData (ctx )
196
+
197
+ context .VerifyCaptcha (ctx , tplSignIn , form )
198
+ if ctx .Written () {
199
+ return
200
+ }
201
+ }
202
+
192
203
u , source , err := auth_service .UserSignIn (form .UserName , form .Password )
193
204
if err != nil {
194
205
if user_model .IsErrUserNotExist (err ) || user_model .IsErrEmailAddressNotExist (err ) {
@@ -383,14 +394,7 @@ func SignUp(ctx *context.Context) {
383
394
384
395
ctx .Data ["SignUpLink" ] = setting .AppSubURL + "/user/sign_up"
385
396
386
- ctx .Data ["EnableCaptcha" ] = setting .Service .EnableCaptcha
387
- ctx .Data ["RecaptchaURL" ] = setting .Service .RecaptchaURL
388
- ctx .Data ["Captcha" ] = context .GetImageCaptcha ()
389
- ctx .Data ["CaptchaType" ] = setting .Service .CaptchaType
390
- ctx .Data ["RecaptchaSitekey" ] = setting .Service .RecaptchaSitekey
391
- ctx .Data ["HcaptchaSitekey" ] = setting .Service .HcaptchaSitekey
392
- ctx .Data ["McaptchaSitekey" ] = setting .Service .McaptchaSitekey
393
- ctx .Data ["McaptchaURL" ] = setting .Service .McaptchaURL
397
+ context .SetCaptchaData (ctx )
394
398
ctx .Data ["PageIsSignUp" ] = true
395
399
396
400
// Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true
@@ -406,14 +410,7 @@ func SignUpPost(ctx *context.Context) {
406
410
407
411
ctx .Data ["SignUpLink" ] = setting .AppSubURL + "/user/sign_up"
408
412
409
- ctx .Data ["EnableCaptcha" ] = setting .Service .EnableCaptcha
410
- ctx .Data ["RecaptchaURL" ] = setting .Service .RecaptchaURL
411
- ctx .Data ["Captcha" ] = context .GetImageCaptcha ()
412
- ctx .Data ["CaptchaType" ] = setting .Service .CaptchaType
413
- ctx .Data ["RecaptchaSitekey" ] = setting .Service .RecaptchaSitekey
414
- ctx .Data ["HcaptchaSitekey" ] = setting .Service .HcaptchaSitekey
415
- ctx .Data ["McaptchaSitekey" ] = setting .Service .McaptchaSitekey
416
- ctx .Data ["McaptchaURL" ] = setting .Service .McaptchaURL
413
+ context .SetCaptchaData (ctx )
417
414
ctx .Data ["PageIsSignUp" ] = true
418
415
419
416
// Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
@@ -427,31 +424,9 @@ func SignUpPost(ctx *context.Context) {
427
424
return
428
425
}
429
426
430
- if setting .Service .EnableCaptcha {
431
- var valid bool
432
- var err error
433
- switch setting .Service .CaptchaType {
434
- case setting .ImageCaptcha :
435
- valid = context .GetImageCaptcha ().VerifyReq (ctx .Req )
436
- case setting .ReCaptcha :
437
- valid , err = recaptcha .Verify (ctx , form .GRecaptchaResponse )
438
- case setting .HCaptcha :
439
- valid , err = hcaptcha .Verify (ctx , form .HcaptchaResponse )
440
- case setting .MCaptcha :
441
- valid , err = mcaptcha .Verify (ctx , form .McaptchaResponse )
442
- default :
443
- ctx .ServerError ("Unknown Captcha Type" , fmt .Errorf ("Unknown Captcha Type: %s" , setting .Service .CaptchaType ))
444
- return
445
- }
446
- if err != nil {
447
- log .Debug ("%s" , err .Error ())
448
- }
449
-
450
- if ! valid {
451
- ctx .Data ["Err_Captcha" ] = true
452
- ctx .RenderWithErr (ctx .Tr ("form.captcha_incorrect" ), tplSignUp , & form )
453
- return
454
- }
427
+ context .VerifyCaptcha (ctx , tplSignUp , form )
428
+ if ctx .Written () {
429
+ return
455
430
}
456
431
457
432
if ! form .IsEmailDomainAllowed () {
0 commit comments