File tree Expand file tree Collapse file tree 9 files changed +41
-0
lines changed Expand file tree Collapse file tree 9 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 55require (
66 code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b
77 code.gitea.io/sdk/gitea v0.15.1
8+ codeberg.org/gusted/mcaptcha v0.0.0-20220722211632-55c1ffff1222
89 gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb
910 gitea.com/go-chi/cache v0.2.0
1011 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
6262code.gitea.io/sdk/gitea v0.11.3 /go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY =
6363code.gitea.io/sdk/gitea v0.15.1 h1:WJreC7YYuxbn0UDaPuWIe/mtiNKTvLN8MLkaw71yx/M =
6464code.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 =
6567contrib.go.opencensus.io/exporter/aws v0.0.0-20181029163544-2befc13012d0 /go.mod h1:uu1P0UCM/6RbsMrgPa98ll8ZcHM858i/AD06a9aLRCA =
6668contrib.go.opencensus.io/exporter/ocagent v0.5.0 /go.mod h1:ImxhfLRpxoYiSq891pBrLVhN+qmP8BTVvdH2YLs7Gl0 =
6769contrib.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 (
1818 "code.gitea.io/gitea/modules/eventsource"
1919 "code.gitea.io/gitea/modules/hcaptcha"
2020 "code.gitea.io/gitea/modules/log"
21+ "code.gitea.io/gitea/modules/mcaptcha"
2122 "code.gitea.io/gitea/modules/password"
2223 "code.gitea.io/gitea/modules/recaptcha"
2324 "code.gitea.io/gitea/modules/session"
@@ -462,6 +463,8 @@ func SignUpPost(ctx *context.Context) {
462463 valid , err = recaptcha .Verify (ctx , form .GRecaptchaResponse )
463464 case setting .HCaptcha :
464465 valid , err = hcaptcha .Verify (ctx , form .HcaptchaResponse )
466+ case setting .MCaptcha :
467+ valid , err = mcaptcha .Verify (ctx , form .McaptchaResponse )
465468 default :
466469 ctx .ServerError ("Unknown Captcha Type" , fmt .Errorf ("Unknown Captcha Type: %s" , setting .Service .CaptchaType ))
467470 return
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import (
1616 "code.gitea.io/gitea/modules/context"
1717 "code.gitea.io/gitea/modules/hcaptcha"
1818 "code.gitea.io/gitea/modules/log"
19+ "code.gitea.io/gitea/modules/mcaptcha"
1920 "code.gitea.io/gitea/modules/recaptcha"
2021 "code.gitea.io/gitea/modules/session"
2122 "code.gitea.io/gitea/modules/setting"
@@ -239,6 +240,8 @@ func LinkAccountPostRegister(ctx *context.Context) {
239240 valid , err = recaptcha .Verify (ctx , form .GRecaptchaResponse )
240241 case setting .HCaptcha :
241242 valid , err = hcaptcha .Verify (ctx , form .HcaptchaResponse )
243+ case setting .MCaptcha :
244+ valid , err = mcaptcha .Verify (ctx , form .McaptchaResponse )
242245 default :
243246 ctx .ServerError ("Unknown Captcha Type" , fmt .Errorf ("Unknown Captcha Type: %s" , setting .Service .CaptchaType ))
244247 return
Original file line number Diff line number Diff line change @@ -401,6 +401,12 @@ func RegisterOpenIDPost(ctx *context.Context) {
401401 return
402402 }
403403 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 )
404410 default :
405411 ctx .ServerError ("Unknown Captcha Type" , fmt .Errorf ("Unknown Captcha Type: %s" , setting .Service .CaptchaType ))
406412 return
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ type RegisterForm struct {
9595 Retype string
9696 GRecaptchaResponse string `form:"g-recaptcha-response"`
9797 HcaptchaResponse string `form:"h-captcha-response"`
98+ McaptchaResponse string `form:"m-captcha-response"`
9899}
99100
100101// Validate validates the fields
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ type SignUpOpenIDForm struct {
3131 Email string `binding:"Required;Email;MaxSize(254)"`
3232 GRecaptchaResponse string `form:"g-recaptcha-response"`
3333 HcaptchaResponse string `form:"h-captcha-response"`
34+ McaptchaResponse string `form:"m-captcha-response"`
3435}
3536
3637// Validate validates the fields
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export async function initMcaptcha() {
55 }
66
77 const { default : mCaptcha } = await import ( /* webpackChunkName: "mcaptcha-vanilla-glue" */ '@mcaptcha/vanilla-glue' ) ;
8+ mCaptcha . INPUT_NAME = 'm-captcha-response' ;
89 const siteKey = siteKeyEl . getAttribute ( 'data-sitekey' ) ;
910
1011 mCaptcha . default ( {
You can’t perform that action at this time.
0 commit comments