More stuff for login and editor

This commit is contained in:
Caleb Gardner
2024-11-09 11:32:16 -06:00
parent 6896266055
commit 18aa193fe7
7 changed files with 51 additions and 15 deletions
+26 -1
View File
@@ -39,4 +39,29 @@ func (e Editor) LoginPage(w http.ResponseWriter, r *http.Request) {
sendContent(w, r, string(dat), "", "")
}
func (e Editor) Editor(w http.ResponseWriter, r *http.Request) {}
func (e Editor) Editor(w http.ResponseWriter, r *http.Request) {
hdr, err := back.ParseHeader(r)
if err == backend.ErrApiKeyUnauthorized || err == backend.ErrTokenUnauthorized || hdr == nil || hdr.User == nil {
if r.Header.Get("HX-Request") == "true" {
w.Header().Set("HX-Location", `{"path":"/login", "target":"#content"}`)
return
}
w.Header().Set("Content-Type", "text/html")
http.Redirect(w, r, "https://darkstorm.tech/login", http.StatusSeeOther)
return
}
page, err := editorFS.Open("embed/editor.html")
defer page.Close()
if err != nil {
log.Println("error getting editor.html:", err)
sendContent(w, r, "error getting page", "", "")
return
}
dat, err := io.ReadAll(page)
if err != nil {
log.Println("error reading editor.html:", err)
sendContent(w, r, "error getting page", "", "")
return
}
sendContent(w, r, string(dat), "", "")
}