#73 change authorization

This commit is contained in:
2024-08-25 22:25:32 +02:00
parent 81548465e7
commit d854dae68f
19 changed files with 589 additions and 187 deletions

View File

@@ -1,20 +1,25 @@
package service
import (
"me-fit/templates"
"database/sql"
"me-fit/template"
"net/http"
"github.com/a-h/templ"
)
func HandleIndexAnd404(w http.ResponseWriter, r *http.Request) {
var comp templ.Component = nil
if r.URL.Path != "/" {
comp = templates.Layout(templates.NotFound())
w.WriteHeader(http.StatusNotFound)
} else {
comp = templates.Layout(templates.Index())
}
func HandleIndexAnd404(db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var comp templ.Component = nil
user_comp := UserInfoComp(verifySessionAndReturnUser(db, r))
comp.Render(r.Context(), w)
if r.URL.Path != "/" {
comp = template.Layout(template.NotFound(), user_comp)
w.WriteHeader(http.StatusNotFound)
} else {
comp = template.Layout(template.Index(), user_comp)
}
comp.Render(r.Context(), w)
}
}