add login page to webserver
This commit is contained in:
@@ -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: ""})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user