File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,14 @@ package routes
33import  (
44"fmt" 
55"github.com/blobs-io/blobsgame/models/user" 
6+ "github.com/blobs-io/blobsgame/utils" 
67"github.com/gofiber/fiber" 
78)
89
910type  RegisterRequestBody  struct  {
1011Username  string  `json:"username"` 
1112Password  string  `json:"password"` 
13+ Token  string  `json:"token"` 
1214}
1315
1416func  Register (ctx  * fiber.Ctx ) {
@@ -19,6 +21,18 @@ func Register(ctx *fiber.Ctx) {
1921return 
2022}
2123
24+ captchaResp , err  :=  utils .RateCaptcha (body .Token )
25+ if  err  !=  nil  {
26+ fmt .Println (err )
27+ ctx .Status (500 ).Write ("Account creation failed. "  +  err .Error ())
28+ return 
29+ }
30+ 
31+ if  ! utils .ValidateCaptcha (captchaResp ) {
32+ ctx .Status (403 ).Write ("Invalid captcha" )
33+ return 
34+ }
35+ 
2236err  =  user .Register (body .Username , body .Password )
2337if  err  !=  nil  {
2438fmt .Println (err )
@@ -27,4 +41,5 @@ func Register(ctx *fiber.Ctx) {
2741}
2842
2943// Successfully registered 
44+ ctx .Redirect ("/login" )
3045}
                         You can’t perform that action at this time. 
           
                  
0 commit comments