Noah Petherbridge
2a8a1df6ab
* Initial codebase (lot of work!) * Uses vanilla Go net/http and implements by hand: session cookies backed by Redis; log in/out; CSRF protection; email verification flow; initial database models (User table)
37 lines
782 B
Go
37 lines
782 B
Go
package templates
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/config"
|
|
"git.kirsle.net/apps/gosocial/pkg/session"
|
|
)
|
|
|
|
// MergeVars mixes in globally available template variables. The http.Request is optional.
|
|
func MergeVars(r *http.Request, m map[string]interface{}) {
|
|
m["Title"] = config.Title
|
|
m["Subtitle"] = config.Subtitle
|
|
m["YYYY"] = time.Now().Year()
|
|
|
|
if r == nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
// MergeUserVars mixes in global template variables: LoggedIn and CurrentUser. The http.Request is optional.
|
|
func MergeUserVars(r *http.Request, m map[string]interface{}) {
|
|
// Defaults
|
|
m["LoggedIn"] = false
|
|
m["CurrentUser"] = nil
|
|
|
|
if r == nil {
|
|
return
|
|
}
|
|
|
|
if user, err := session.CurrentUser(r); err == nil {
|
|
m["LoggedIn"] = true
|
|
m["CurrentUser"] = user
|
|
}
|
|
}
|