Created package "calls" and verification for frontend and calls

This commit is contained in:
2024-08-18 11:20:06 +02:00
parent 5b41892dff
commit cd27349d04
11 changed files with 194 additions and 140 deletions

View 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
}