diff options
| author | Bobby <[email protected]> | 2025-07-13 14:22:20 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-07-13 14:22:20 +0530 |
| commit | 3d7f8602d45583f25e2428bf6f8123453646dc08 (patch) | |
| tree | ecd707d298099ae9fda55efc3f0d1daf48f7b6e9 /processors/user.go | |
| parent | bf112649d039f8f02e2135a74d8b506f7c31c784 (diff) | |
| download | imageboard-3d7f8602d45583f25e2428bf6f8123453646dc08.tar.xz imageboard-3d7f8602d45583f25e2428bf6f8123453646dc08.zip | |
registration controllers and email sending support
Diffstat (limited to 'processors/user.go')
| -rw-r--r-- | processors/user.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/processors/user.go b/processors/user.go new file mode 100644 index 0000000..b875c89 --- /dev/null +++ b/processors/user.go @@ -0,0 +1,43 @@ +package processors + +import ( + "imageboard/database" + "imageboard/models" + "imageboard/session" + + "github.com/gofiber/fiber/v2" +) + +func UserContextProcessor(ctx *fiber.Ctx) error { + var user *models.User + + sess, err := session.Store.Get(ctx) + if err == nil { + var userID uint + if id := sess.Get("user_id"); id != nil { + switch v := id.(type) { + case uint: + userID = v + case int: + userID = uint(v) + case int64: + userID = uint(v) + case float64: + userID = uint(v) + } + } + + if userID != 0 { + dbUser, err := database.GetUserByID(userID) + if err == nil && dbUser != nil { + dbUser.UpdateLastUserActivity(database.DB) + user = dbUser + } + } + } + + ctx.Locals("User", user) + ctx.Locals("IsAuthenticated", user != nil) + + return ctx.Next() +} |
