From b2f5ebdc623c5cf278215ef2da0ecefaba2f5d65 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 13 Feb 2025 01:52:16 +0800 Subject: login: Stub login page --- http_handle_login.go | 18 ++++++++++++ http_server.go | 16 +++++++++-- static/style.css | 73 ++++++++++++++++++++++++++++++++++++++++++++++- templates/login.html.tmpl | 54 +++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 http_handle_login.go create mode 100644 templates/login.html.tmpl diff --git a/http_handle_login.go b/http_handle_login.go new file mode 100644 index 0000000..ef094f1 --- /dev/null +++ b/http_handle_login.go @@ -0,0 +1,18 @@ +package main + +import ( + "net/http" +) + +func handle_login(w http.ResponseWriter, r *http.Request, params map[string]any) { + if r.Method != "POST" { + err := templates.ExecuteTemplate(w, "login", params) + if err != nil { + _, _ = w.Write([]byte("Error rendering template: " + err.Error())) + return + } + } + + _ = r.PostFormValue("username") + _ = r.PostFormValue("password") +} diff --git a/http_server.go b/http_server.go index 4d2d77c..ddbe8ce 100644 --- a/http_server.go +++ b/http_server.go @@ -34,12 +34,11 @@ func (router *http_router_t) ServeHTTP(w http.ResponseWriter, r *http.Request) { switch segments[1] { case "static": static_handler.ServeHTTP(w, r) + return case "source": source_handler.ServeHTTP(w, r) - default: - http.Error(w, fmt.Sprintf("Unknown system module type: %s", segments[1]), http.StatusNotFound) + return } - return } params := make(map[string]any) @@ -52,6 +51,17 @@ func (router *http_router_t) ServeHTTP(w http.ResponseWriter, r *http.Request) { params["user_id"] = string(_user_id) } + if segments[0] == ":" { + switch segments[1] { + case "login": + handle_login(w, r, params) + return + default: + http.Error(w, fmt.Sprintf("Unknown system module type: %s", segments[1]), http.StatusNotFound) + return + } + } + fmt.Printf("%#v\n", params) separator_index := -1 diff --git a/static/style.css b/static/style.css index 40f130a..4ebcdfd 100644 --- a/static/style.css +++ b/static/style.css @@ -11,6 +11,10 @@ html { --text-decoration-color: hsl(0, 0%, 72%); --darker-box-background-color: hsl(0, 0%, 92%); --lighter-box-background-color: hsl(0, 0%, 95%); + --primary-color: hsl(320, 50%, 36%); + --primary-color-contrast: hsl(320, 0%, 100%); + --danger-color: hsl(0, 50%, 36%); + --danger-color-contrast: hsl(0, 0%, 100%); } @media (prefers-color-scheme: dark) { html { @@ -67,7 +71,7 @@ td, th { padding: 3px 5px; border: var(--lighter-border-color) solid 1px; } -th { +th, thead, tfoot { background-color: var(--lighter-box-background-color); } th[scope=row] { @@ -164,3 +168,70 @@ pre.chunk { .file-header { font-family: monospace; } + +textarea { + box-sizing: border-box; + background-color: var(--lighter-box-background-color); + resize: vertical; +} +textarea, +input[type=text], +input[type=password] { + font-family: sans-serif; + font-size: smaller; + background-color: var(--lighter-box-background-color); + color: var(--text-color); + border: none; + padding: 0.3rem; + width: 100%; + box-sizing: border-box; +} +td.tdinput, th.tdinput { + padding: 0; +} +td.tdinput textarea, +td.tdinput input[type=text], +td.tdinput input[type=password], +th.tdinput textarea, +th.tdinput input[type=text], +th.tdinput input[type=password] { + background-color: transparent; +} +.btn-primary { + background: var(--primary-color); + color: var(--primary-color-contrast); + border: var(--lighter-border-color) 1px solid; + font-weight: bold; +} +.btn-danger { + background: var(--danger-color); + color: var(--danger-color-contrast); + border: var(--lighter-border-color) 1px solid; + font-weight: bold; +} +.btn-white { + background: var(--primary-color-contrast); + color: var(--primary-color); + border: var(--lighter-border-color) 1px solid; +} +.btn-normal, +input[type=file]::file-selector-button { + background: var(--lighter-box-background-color); + border: var(--lighter-border-color) 1px solid !important; + color: var(--light-text-color); +} +.btn, .btn-white, .btn-danger, .btn-normal, .btn-primary, +input[type=submit], +input[type=file]::file-selector-button { + display: inline-block; + width: auto; + min-width: fit-content; + border-radius: 0; + padding: .1rem .75rem; + font-size: 0.9rem; + transition: background .1s linear; + cursor: pointer; +} +a.btn, a.btn-white, a.btn-danger, a.btn-normal, a.btn-primary { + text-decoration: none; +} diff --git a/templates/login.html.tmpl b/templates/login.html.tmpl new file mode 100644 index 0000000..ca9d87e --- /dev/null +++ b/templates/login.html.tmpl @@ -0,0 +1,54 @@ +{{- define "login" -}} + + + + {{ template "head_common" . }} + Login – Lindenii Forge + + +
+
+ + + + + + + + + + + + + + + + + + + + + +
+ Password Authentication +
Username + +
Password + +
+
+
+
+
+ +
+
+
+
+
+ + + +{{- end -}} -- cgit v1.2.3