cpolis/cmd/frontend/verification.go

23 lines
661 B
Go
Raw Normal View History

package frontend
import (
"html/template"
"net/http"
"github.com/gorilla/sessions"
b "streifling.com/jason/cpolis/cmd/backend"
)
// getSession is used for verifying that the user is logged in and returns their session and an error.
func getSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.CookieStore) (*sessions.Session, error) {
session, err := s.Get(r, "cookie")
if err != nil {
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
tmpl, tmplErr := template.ParseFiles(c.WebDir + "/templates/login.html")
template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg)
return nil, err
}
return session, nil
}