Fixed a bug that let users get around verification.

This commit is contained in:
Jason Streifling 2024-08-18 11:40:03 +02:00
parent 61bfa85b13
commit 8115c50974

View File

@ -1,6 +1,7 @@
package frontend package frontend
import ( import (
"errors"
"html/template" "html/template"
"net/http" "net/http"
@ -10,13 +11,19 @@ import (
// getSession is used for verifying that the user is logged in and returns their session and an error. // 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) { func getSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.CookieStore) (*sessions.Session, error) {
msg := "Keine gültige Session. Bitte erneut anmelden."
tmpl, tmplErr := template.ParseFiles(c.WebDir+"/templates/index.html", c.WebDir+"/templates/login.html")
session, err := s.Get(r, "cookie") session, err := s.Get(r, "cookie")
if err != nil { 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) template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg)
return nil, err return nil, err
} }
if session.IsNew {
template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg)
return session, errors.New("error: no existing session")
}
return session, nil return session, nil
} }