Skip to content

Commit a765650

Browse files
committed
finish register route
1 parent 215b6bb commit a765650

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

http/web/routes/register.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package routes
33
import (
44
"fmt"
55
"github.com/blobs-io/blobsgame/models/user"
6+
"github.com/blobs-io/blobsgame/utils"
67
"github.com/gofiber/fiber"
78
)
89

910
type RegisterRequestBody struct {
1011
Username string `json:"username"`
1112
Password string `json:"password"`
13+
Token string `json:"token"`
1214
}
1315

1416
func Register(ctx *fiber.Ctx) {
@@ -19,6 +21,18 @@ func Register(ctx *fiber.Ctx) {
1921
return
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+
2236
err = user.Register(body.Username, body.Password)
2337
if err != nil {
2438
fmt.Println(err)
@@ -27,4 +41,5 @@ func Register(ctx *fiber.Ctx) {
2741
}
2842

2943
// Successfully registered
44+
ctx.Redirect("/login")
3045
}

0 commit comments

Comments
 (0)