Finally get login working.

This commit is contained in:
2025-03-26 08:36:11 +00:00
parent e55508661c
commit e3f3d73fdd
6 changed files with 96 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ package helpers
import (
"html/template"
"log"
"net/http"
"synlotto-website/models"
)
@@ -37,10 +38,18 @@ func TemplateContext(w http.ResponseWriter, r *http.Request) map[string]interfac
}
var currentUser *models.User
if userId, ok := session.Values["user_id"].(int); ok {
currentUser = models.GetUserByID(userId)
switch v := session.Values["user_id"].(type) {
case int:
currentUser = models.GetUserByID(v)
case int64:
currentUser = models.GetUserByID(int(v))
default:
currentUser = nil
}
log.Printf("🧪 TemplateContext user: %#v", currentUser)
return map[string]interface{}{
"Flash": flash,
"User": currentUser,