File tree 9 files changed +41
-0
lines changed 9 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 5
5
require (
6
6
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b
7
7
code.gitea.io/sdk/gitea v0.15.1
8
+ codeberg.org/gusted/mcaptcha v0.0.0-20220722211632-55c1ffff1222
8
9
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb
9
10
gitea.com/go-chi/cache v0.2.0
10
11
gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5
Original file line number Diff line number Diff line change @@ -62,6 +62,8 @@ code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b/go.mod h1:zcNbT/aJE
62
62
code.gitea.io/sdk/gitea v0.11.3 /go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY =
63
63
code.gitea.io/sdk/gitea v0.15.1 h1:WJreC7YYuxbn0UDaPuWIe/mtiNKTvLN8MLkaw71yx/M =
64
64
code.gitea.io/sdk/gitea v0.15.1 /go.mod h1:klY2LVI3s3NChzIk/MzMn7G1FHrfU7qd63iSMVoHRBA =
65
+ codeberg.org/gusted/mcaptcha v0.0.0-20220722211632-55c1ffff1222 h1:PCW4i+gnQ9XxF8V+nBch3KWdGe4MiP3xXUCA/z0jhHk =
66
+ codeberg.org/gusted/mcaptcha v0.0.0-20220722211632-55c1ffff1222 /go.mod h1:IIAjsijsd8q1isWX8MACefDEgTQslQ4stk2AeeTt3kM =
65
67
contrib.go.opencensus.io/exporter/aws v0.0.0-20181029163544-2befc13012d0 /go.mod h1:uu1P0UCM/6RbsMrgPa98ll8ZcHM858i/AD06a9aLRCA =
66
68
contrib.go.opencensus.io/exporter/ocagent v0.5.0 /go.mod h1:ImxhfLRpxoYiSq891pBrLVhN+qmP8BTVvdH2YLs7Gl0 =
67
69
contrib.go.opencensus.io/exporter/stackdriver v0.12.1 /go.mod h1:iwB6wGarfphGGe/e5CWqyUk/cLzKnWsOKPVW3no6OTw =
Original file line number Diff line number Diff line change
1
+ package mcaptcha
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+
7
+ "code.gitea.io/gitea/modules/setting"
8
+
9
+ "codeberg.org/gusted/mcaptcha"
10
+ )
11
+
12
+ func Verify (ctx context.Context , token string ) (bool , error ) {
13
+ valid , err := mcaptcha .Verify (ctx , & mcaptcha.VerifyOpts {
14
+ InstanceURL : setting .Service .McaptchaURL ,
15
+ Sitekey : setting .Service .McaptchaSitekey ,
16
+ Secret : setting .Service .McaptchaSecret ,
17
+ Token : token ,
18
+ })
19
+ if err != nil {
20
+ return false , fmt .Errorf ("wasn't able to verify mCaptcha: %v" , err )
21
+ }
22
+ return valid , nil
23
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
18
18
"code.gitea.io/gitea/modules/eventsource"
19
19
"code.gitea.io/gitea/modules/hcaptcha"
20
20
"code.gitea.io/gitea/modules/log"
21
+ "code.gitea.io/gitea/modules/mcaptcha"
21
22
"code.gitea.io/gitea/modules/password"
22
23
"code.gitea.io/gitea/modules/recaptcha"
23
24
"code.gitea.io/gitea/modules/session"
@@ -462,6 +463,8 @@ func SignUpPost(ctx *context.Context) {
462
463
valid , err = recaptcha .Verify (ctx , form .GRecaptchaResponse )
463
464
case setting .HCaptcha :
464
465
valid , err = hcaptcha .Verify (ctx , form .HcaptchaResponse )
466
+ case setting .MCaptcha :
467
+ valid , err = mcaptcha .Verify (ctx , form .McaptchaResponse )
465
468
default :
466
469
ctx .ServerError ("Unknown Captcha Type" , fmt .Errorf ("Unknown Captcha Type: %s" , setting .Service .CaptchaType ))
467
470
return
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import (
16
16
"code.gitea.io/gitea/modules/context"
17
17
"code.gitea.io/gitea/modules/hcaptcha"
18
18
"code.gitea.io/gitea/modules/log"
19
+ "code.gitea.io/gitea/modules/mcaptcha"
19
20
"code.gitea.io/gitea/modules/recaptcha"
20
21
"code.gitea.io/gitea/modules/session"
21
22
"code.gitea.io/gitea/modules/setting"
@@ -239,6 +240,8 @@ func LinkAccountPostRegister(ctx *context.Context) {
239
240
valid , err = recaptcha .Verify (ctx , form .GRecaptchaResponse )
240
241
case setting .HCaptcha :
241
242
valid , err = hcaptcha .Verify (ctx , form .HcaptchaResponse )
243
+ case setting .MCaptcha :
244
+ valid , err = mcaptcha .Verify (ctx , form .McaptchaResponse )
242
245
default :
243
246
ctx .ServerError ("Unknown Captcha Type" , fmt .Errorf ("Unknown Captcha Type: %s" , setting .Service .CaptchaType ))
244
247
return
Original file line number Diff line number Diff line change @@ -401,6 +401,12 @@ func RegisterOpenIDPost(ctx *context.Context) {
401
401
return
402
402
}
403
403
valid , err = hcaptcha .Verify (ctx , form .HcaptchaResponse )
404
+ case setting .MCaptcha :
405
+ if err := ctx .Req .ParseForm (); err != nil {
406
+ ctx .ServerError ("" , err )
407
+ return
408
+ }
409
+ valid , err = hcaptcha .Verify (ctx , form .HcaptchaResponse )
404
410
default :
405
411
ctx .ServerError ("Unknown Captcha Type" , fmt .Errorf ("Unknown Captcha Type: %s" , setting .Service .CaptchaType ))
406
412
return
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ type RegisterForm struct {
95
95
Retype string
96
96
GRecaptchaResponse string `form:"g-recaptcha-response"`
97
97
HcaptchaResponse string `form:"h-captcha-response"`
98
+ McaptchaResponse string `form:"m-captcha-response"`
98
99
}
99
100
100
101
// Validate validates the fields
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ type SignUpOpenIDForm struct {
31
31
Email string `binding:"Required;Email;MaxSize(254)"`
32
32
GRecaptchaResponse string `form:"g-recaptcha-response"`
33
33
HcaptchaResponse string `form:"h-captcha-response"`
34
+ McaptchaResponse string `form:"m-captcha-response"`
34
35
}
35
36
36
37
// Validate validates the fields
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export async function initMcaptcha() {
5
5
}
6
6
7
7
const { default : mCaptcha } = await import ( /* webpackChunkName: "mcaptcha-vanilla-glue" */ '@mcaptcha/vanilla-glue' ) ;
8
+ mCaptcha . INPUT_NAME = 'm-captcha-response' ;
8
9
const siteKey = siteKeyEl . getAttribute ( 'data-sitekey' ) ;
9
10
10
11
mCaptcha . default ( {
You can’t perform that action at this time.
0 commit comments