add login page to webserver

This commit is contained in:
2026-07-31 12:45:43 -07:00
parent e8b422e390
commit e53631a65b
4 changed files with 78 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
package webserver
import (
"net/http"
"strings"
"text/template"
)
type LoginPageData struct {
IsHiddenClassList string
}
func loginHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
tmpl := template.Must(template.ParseFiles("webserver/pages/login_page.html"))
if r.Method == http.MethodGet {
tmpl.Execute(w, LoginPageData{IsHiddenClassList: "hidden"})
return
}
if r.Method == http.MethodPost {
username := r.FormValue("username")
if strings.Contains(username, "/") {
tmpl.Execute(w, LoginPageData{IsHiddenClassList: ""})
}
}
}