more changes but unsure of state had to trash last set fof changes and try repair.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"synlotto-website/models"
|
||||
"synlotto-website/storage"
|
||||
|
||||
"github.com/gorilla/csrf"
|
||||
)
|
||||
@@ -50,6 +51,8 @@ func TemplateContext(w http.ResponseWriter, r *http.Request) map[string]interfac
|
||||
|
||||
var currentUser *models.User
|
||||
var isAdmin bool
|
||||
var notificationCount int
|
||||
var notifications []models.Notification
|
||||
|
||||
switch v := session.Values["user_id"].(type) {
|
||||
case int:
|
||||
@@ -60,13 +63,17 @@ func TemplateContext(w http.ResponseWriter, r *http.Request) map[string]interfac
|
||||
|
||||
if currentUser != nil {
|
||||
isAdmin = currentUser.IsAdmin
|
||||
notificationCount = storage.GetNotificationCount(currentUser.Id)
|
||||
notifications = storage.GetRecentNotifications(currentUser.Id, 15)
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"CSRFField": csrf.TemplateField(r),
|
||||
"Flash": flash,
|
||||
"User": currentUser,
|
||||
"IsAdmin": isAdmin,
|
||||
"CSRFField": csrf.TemplateField(r),
|
||||
"Flash": flash,
|
||||
"User": currentUser,
|
||||
"IsAdmin": isAdmin,
|
||||
"NotificationCount": notificationCount,
|
||||
"Notifications": notifications,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,3 +107,9 @@ func rangeClass(n int) string {
|
||||
return "50-plus"
|
||||
}
|
||||
}
|
||||
|
||||
func SetFlash(w http.ResponseWriter, r *http.Request, message string) {
|
||||
session, _ := GetSession(w, r)
|
||||
session.Values["flash"] = message
|
||||
session.Save(r, w)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user