diff --git a/account.go b/admin/account.go similarity index 93% rename from account.go rename to admin/account.go index e0ab768..c90beb9 100644 --- a/account.go +++ b/admin/account.go @@ -1,415 +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í
-Administrátorské rozhraní
+