Use proper filepaths

This commit is contained in:
2025-01-19 09:31:19 +01:00
parent 62e75eaea8
commit b8fd81a86d
8 changed files with 45 additions and 38 deletions

View File

@@ -7,6 +7,7 @@ import (
"html/template"
"log"
"net/http"
"path/filepath"
"time"
"github.com/google/uuid"
@@ -67,7 +68,7 @@ func StartSessions() (map[string]*Session, chan string) {
// their session and an error. It also handles cases where the user is not
// logged in.
func ManageSession(w http.ResponseWriter, r *http.Request, c *b.Config, s map[string]*Session) (*Session, error) {
tmpl, tmplErr := template.ParseFiles(c.WebDir+"/templates/index.html", c.WebDir+"/templates/login.html")
tmpl, tmplErr := template.ParseFiles(filepath.Join(c.WebDir, "templates", "index.html"), filepath.Join(c.WebDir, "templates", "login.html"))
cookie, err := r.Cookie("cpolis_session")
if err != nil {
@@ -124,7 +125,7 @@ func Login(c *b.Config, db *b.DB, s map[string]*Session, sessionExpiryChan chan
s[session.cookie.Value] = session
http.SetCookie(w, session.cookie)
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
tmpl, err := template.ParseFiles(filepath.Join(c.WebDir, "templates", "hub.html"))
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -135,7 +136,7 @@ func Login(c *b.Config, db *b.DB, s map[string]*Session, sessionExpiryChan chan
func Logout(c *b.Config, s map[string]*Session) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
tmpl, tmplErr := template.ParseFiles(c.WebDir + "/templates/login.html")
tmpl, tmplErr := template.ParseFiles(filepath.Join(c.WebDir, "templates", "login.html"))
cookie, err := r.Cookie("cpolis_session")
if err != nil {