diff options
author | Vikas Kushwaha <dev@vikas.rocks> | 2025-02-11 16:31:08 +0530 |
---|---|---|
committer | Vikas Kushwaha <dev@vikas.rocks> | 2025-02-11 16:31:08 +0530 |
commit | 57eb8f6712361a3bf75983ce153fac4846dc0273 (patch) | |
tree | 269a168d59c917c4e313c819e2b4c3ff8175f912 /cmd/web/controller/htmx/sign-up.go |
Initial commit
Diffstat (limited to 'cmd/web/controller/htmx/sign-up.go')
-rw-r--r-- | cmd/web/controller/htmx/sign-up.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/cmd/web/controller/htmx/sign-up.go b/cmd/web/controller/htmx/sign-up.go new file mode 100644 index 0000000..6bf9a3f --- /dev/null +++ b/cmd/web/controller/htmx/sign-up.go @@ -0,0 +1,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) +} |