Adding login form and handler

This commit is contained in:
collin 2025-07-10 09:35:25 +02:00
parent 2b6449f61b
commit a6d9a99241
No known key found for this signature in database
3 changed files with 8 additions and 2 deletions

View file

@ -12,7 +12,7 @@
<label for="password">Password</label>
<input type="password" name="password" id="password">
<button onclick="login">Login</button>
<button onclick="login()">Login</button>
</div>
<script src="/login.js"></script>
</body>

View file

@ -2,6 +2,6 @@ function login() {
const usernameInput = document.getElementById('username');
const passwordInput = document.getElementById('password');
const token = btoa(`${usernameInput.textContent}:${passwordInput.textContent}`);
const token = btoa(`${usernameInput.value}:${passwordInput.value}`);
document.cookie = `token=${String(token)}; path=/`;
}

View file

@ -158,6 +158,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case r.Method == "GET" && r.URL.Path == "/rsvps_list":
getStaticFile("./client/rsvps_list.html", "text/html", w)
case r.Method == "GET" && r.URL.Path == "/login":
getStaticFile("./client/login.html", "text/html", w)
case r.Method == "GET" && r.URL.Path == "/index.js":
getStaticFile("./client/index.js", "text/javascript", w)
@ -167,6 +170,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case r.Method == "GET" && r.URL.Path == "/rsvps_list.js":
getStaticFile("./client/rsvps_list.js", "text/javascript", w)
case r.Method == "GET" && r.URL.Path == "/login.js":
getStaticFile("./client/login.js", "text/javascript", w)
case r.Method == "GET" && r.URL.Path == "/style.css":
getStaticFile("./client/style.css", "text/css", w)