1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package HTMXController
import (
"projecty/cmd/web/model"
"projecty/internal/authentication"
"projecty/internal/database"
"projecty/internal/helper"
"github.com/gofiber/fiber/v2"
)
func SignUpPage(c *fiber.Ctx) error {
return c.Render("sign-up/htmx-sign-up-page", fiber.Map{
"PageTitle": "Sign Up",
"NavBarActive": "sign-up",
"FiberCtx": c,
}, "layouts/app-htmx")
}
func SignUpAction(c *fiber.Ctx) error {
username := c.FormValue("username")
email := c.FormValue("email")
password := c.FormValue("password")
if email == "" || username == "" || password == "" {
return c.Render("sign-up/partials/sign-up-form", fiber.Map{
"Errors": []string{
"Username, email, and password cannot be null.",
},
"IsOob": true,
}, "layouts/app-htmx")
}
user := model.User{Username: username, Email: email, Password: password, Name: username}
user.HashPassword()
db := database.Get()
db.Create(&user)
authentication.AuthStore(c, user.ID)
return helper.HTMXRedirectTo("/", "/htmx/home", c)
}
|