Circular dependancy issue when working on hardening

This commit is contained in:
2025-03-25 16:43:16 +00:00
parent 1a531af4f8
commit b58a8bdb82
8 changed files with 96 additions and 23 deletions

View File

@@ -2,6 +2,8 @@ package helpers
import (
"html/template"
"net/http"
"synlotto-website/models"
)
func TemplateFuncs() template.FuncMap {
@@ -23,3 +25,24 @@ func TemplateFuncs() template.FuncMap {
},
}
}
func TemplateContext(w http.ResponseWriter, r *http.Request) map[string]interface{} {
session, _ := GetSession(w, r)
var flash string
if f, ok := session.Values["flash"].(string); ok {
flash = f
delete(session.Values, "flash")
session.Save(r, w)
}
var currentUser *models.User
if userId, ok := session.Values["user_id"].(int); ok {
currentUser = models.GetUserByID(userId)
}
return map[string]interface{}{
"Flash": flash,
"User": currentUser,
}
}