ADD: added initial page with login

This commit is contained in:
hwinkel
2025-05-20 22:58:31 +02:00
parent 214ab55ad2
commit a330291456
25 changed files with 1064 additions and 35 deletions

View File

@@ -0,0 +1,38 @@
package auth
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
type LoginRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}
type LoginResponse struct {
Token string `json:"token"`
}
func LoginHandler(c *gin.Context) {
var req LoginRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Bad request"})
return
}
// Systemnutzer
if req.Email == "systemuser@example.com" {
token, err := CreateJWT("system-user-id", req.Email, "admin", time.Hour*24*7)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token error"})
return
}
c.JSON(http.StatusOK, LoginResponse{Token: token})
return
}
c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid credentials"})
}