forked from jason/cpolis
Created package "calls" and verification for frontend and calls
This commit is contained in:
22
cmd/frontend/verification.go
Normal file
22
cmd/frontend/verification.go
Normal file
@ -0,0 +1,22 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user