From d3581993a732ffae5a1a5a0507199df902c32664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Dvo=C5=99=C3=A1k?= <150935816+Dvorinka@users.noreply.github.com> Date: Mon, 26 May 2025 11:19:42 +0200 Subject: [PATCH] Add files via upload --- account.go | 415 ++++++++++++++++++++++++++++++ admin.go | 733 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 222 +++++++++++++++- main.go | 21 ++ 4 files changed, 1389 insertions(+), 2 deletions(-) create mode 100644 account.go create mode 100644 admin.go diff --git a/account.go b/account.go new file mode 100644 index 0000000..e0ab768 --- /dev/null +++ b/account.go @@ -0,0 +1,415 @@ +package main + +import ( + "crypto/rand" + "encoding/base64" + "encoding/json" + "net/http" + "time" +) + +type User struct { + Username string `json:"username"` + Password string `json:"password"` + Role string `json:"role"` +} + +type Session struct { + Token string + Username string + Role string + ExpiresAt time.Time +} + +type LoginRequest struct { + Username string `json:"username"` + Password string `json:"password"` +} + +type LoginResponse struct { + Success bool `json:"success"` + Message string `json:"message"` + Token string `json:"token,omitempty"` + Role string `json:"role,omitempty"` +} + +// In-memory storage (replace with database in production) +var ( + users = map[string]User{ + "admin": { + Username: "admin", + Password: "admin123", // In production, use hashed passwords + Role: "admin", + }, + } + sessions = make(map[string]Session) +) + +func generateToken() (string, error) { + bytes := make([]byte, 32) + if _, err := rand.Read(bytes); err != nil { + return "", err + } + return base64.URLEncoding.EncodeToString(bytes), nil +} + +func handleLogin(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + if r.Method == "GET" { + // Serve login page + tmpl := ` + +
+ + +Administrátorské rozhraní
+