@@ -77,6 +77,10 @@ func (ws *WebServer) handlerCreateUser(ctx *routing.Context) error {
77
77
return jsonError (ctx , err , fasthttp .StatusBadRequest )
78
78
}
79
79
80
+ if ok , err := ws .validateReCaptcha (ctx , & data .reCaptchaResponse ); ! ok {
81
+ return err
82
+ }
83
+
80
84
if data .UserName == "" || data .Password == "" || len (data .Password ) < 8 {
81
85
return jsonError (ctx , errInvalidArguments , fasthttp .StatusBadRequest )
82
86
}
@@ -271,6 +275,14 @@ func (ws *WebServer) handlerPostMail(ctx *routing.Context) error {
271
275
return jsonResponse (ctx , nil , fasthttp .StatusOK )
272
276
}
273
277
278
+ recUser , err := ws .db .GetUser (- 1 , mail .MailAddress )
279
+ if err != nil {
280
+ return jsonError (ctx , err , fasthttp .StatusInternalServerError )
281
+ }
282
+ if recUser != nil && recUser .UID != user .UID {
283
+ return jsonError (ctx , errEmailAlreadyTaken , fasthttp .StatusBadRequest )
284
+ }
285
+
274
286
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
275
287
token , err := random .String (16 , charset )
276
288
if err != nil {
@@ -374,6 +386,10 @@ func (ws *WebServer) handlerPostPwResetConfirm(ctx *routing.Context) error {
374
386
return jsonError (ctx , fmt .Errorf ("invalid token" ), fasthttp .StatusBadRequest )
375
387
}
376
388
389
+ if ok , err := ws .validateReCaptcha (ctx , & data .reCaptchaResponse ); ! ok {
390
+ return err
391
+ }
392
+
377
393
uID , ok := ws .pwReset .GetValue (data .Token ).(snowflake.ID )
378
394
if ! ok {
379
395
return jsonError (ctx , fmt .Errorf ("wrong data struct in timedmap" ), fasthttp .StatusInternalServerError )
@@ -388,39 +404,6 @@ func (ws *WebServer) handlerPostPwResetConfirm(ctx *routing.Context) error {
388
404
return jsonError (ctx , fmt .Errorf ("unknown user" ), fasthttp .StatusBadRequest )
389
405
}
390
406
391
- errCheckFailed := fmt .Errorf ("security check failed" )
392
- if len (data .PageNames ) < 3 || data .PageNames [0 ] == "" || data .PageNames [1 ] == "" || data .PageNames [2 ] == "" {
393
- return jsonError (ctx , errCheckFailed , fasthttp .StatusBadRequest )
394
- }
395
-
396
- pages , err := ws .db .GetPages (uID , "" , "" , nil )
397
- if err != nil {
398
- return jsonError (ctx , err , fasthttp .StatusInternalServerError )
399
- }
400
-
401
- checkMap := make (map [string ]interface {})
402
- for _ , guess := range data .PageNames {
403
- if _ , ok := checkMap [guess ]; ok {
404
- return jsonError (ctx , errCheckFailed , fasthttp .StatusBadRequest )
405
- }
406
- checkMap [guess ] = nil
407
- }
408
-
409
- var guessed int
410
-
411
- for _ , page := range pages {
412
- for i , guess := range data .PageNames {
413
- if checkPageName (page .Title , guess , 0.2 ) {
414
- guessed ++
415
- data .PageNames [i ] = ""
416
- }
417
- }
418
- }
419
-
420
- if guessed < 3 {
421
- return jsonError (ctx , errCheckFailed , fasthttp .StatusBadRequest )
422
- }
423
-
424
407
ws .pwReset .Remove (data .Token )
425
408
426
409
var passStr string
@@ -640,6 +623,17 @@ func (ws *WebServer) handlerGetVersion(ctx *routing.Context) error {
640
623
}, fasthttp .StatusOK )
641
624
}
642
625
626
+ // GET /recaptchainfo
627
+ func (ws * WebServer ) handlerGetReCaptchaInfo (ctx * routing.Context ) error {
628
+ if ws .config .ReCaptcha == nil || ws .config .ReCaptcha .SiteKey == "" {
629
+ return jsonError (ctx , errors .New ("not configured" ), fasthttp .StatusBadRequest )
630
+ }
631
+
632
+ return jsonCachableResponse (ctx , map [string ]string {
633
+ "sitekey" : ws .config .ReCaptcha .SiteKey ,
634
+ }, fasthttp .StatusOK )
635
+ }
636
+
643
637
// -----------------------------------------------------
644
638
// --- FAVORITES ---
645
639
0 commit comments