summaryrefslogtreecommitdiff
path: root/nexus/controllers/auth/register.go
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-03-29 22:52:46 +0530
committerBobby <[email protected]>2026-03-29 22:52:46 +0530
commit9eb9b7f4bd552a641235764f66483e1f940fcfd9 (patch)
treeda520b923b5e6758d5457b6233dd6671fc640914 /nexus/controllers/auth/register.go
parent65a143a0871c35989b7c7ea6723d39a0585c089e (diff)
downloadechoes-of-vaelun-main.tar.xz
echoes-of-vaelun-main.zip
feat: nexus account manager scaffold with auth, characters, realmsHEADmain
Diffstat (limited to 'nexus/controllers/auth/register.go')
-rw-r--r--nexus/controllers/auth/register.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/nexus/controllers/auth/register.go b/nexus/controllers/auth/register.go
new file mode 100644
index 0000000..6436073
--- /dev/null
+++ b/nexus/controllers/auth/register.go
@@ -0,0 +1,48 @@
+package auth
+
+import (
+ "nexus/services/auth"
+ "nexus/sessions"
+ authTypes "nexus/types/auth"
+ "nexus/utils/collections"
+ "nexus/utils/meta"
+ "nexus/utils/shortcuts"
+
+ "github.com/gofiber/fiber/v2"
+)
+
+func Register(context *fiber.Ctx) error {
+ body, err := meta.Body[authTypes.RegisterRequest](context)
+ if err != nil {
+ return shortcuts.RedirectWithFlash(context, "register", collections.Record[string, any]{
+ "Error": err.Error(),
+ })
+ }
+
+ req := meta.Request(context)
+
+ account, serviceErr := auth.Register(body)
+ if serviceErr != nil {
+ return shortcuts.RedirectWithFlash(context, "register", collections.Record[string, any]{
+ "Error": serviceErr.Message,
+ })
+ }
+
+ session, serviceErr := auth.Login(authTypes.LoginRequest{
+ Email: body.Email,
+ Password: body.Password,
+ }, req.IP, req.Header("User-Agent"))
+ if serviceErr != nil {
+ return shortcuts.Redirect(context, "login")
+ }
+
+ sess := meta.Session(context)
+ if err := sessions.CreateSession(sess, account.ID); err != nil {
+ return shortcuts.RedirectWithFlash(context, "login", collections.Record[string, any]{
+ "Error": ErrSessionCreate,
+ })
+ }
+
+ _ = session
+ return shortcuts.Redirect(context, "account")
+}