chore: update
This commit is contained in:
@@ -30,10 +30,16 @@ func NewHandler(users UserStore, sessions session.Manager, iss *Issuer, secure b
|
||||
type loginRequest struct {
|
||||
Username string
|
||||
Password string
|
||||
// Role : page de connexion utilisée ("admin" ou "client"). La page
|
||||
// admin et la page client sont désormais séparées côté front — un
|
||||
// compte client ne peut pas se connecter depuis la page admin et
|
||||
// inversement, même avec des identifiants valides.
|
||||
Role Role `json:"role" binding:"required,oneof=admin client"`
|
||||
}
|
||||
|
||||
// Login authentifie, ouvre une session Redis et pose le cookie httpOnly.
|
||||
// Réponse volontairement uniforme (pas d'énumération d'utilisateurs).
|
||||
// Réponse volontairement uniforme (pas d'énumération d'utilisateurs, ni du
|
||||
// rôle réel du compte en cas de connexion depuis la mauvaise page).
|
||||
func (h *Handler) Login(c *gin.Context) {
|
||||
var req loginRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -50,7 +56,7 @@ func (h *Handler) Login(c *gin.Context) {
|
||||
}
|
||||
|
||||
ok, err := VerifyPassword(req.Password, user.PasswordHash)
|
||||
if err != nil || !ok {
|
||||
if err != nil || !ok || user.Role != req.Role {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "identifiants invalides"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -10,6 +10,14 @@ type User struct {
|
||||
Role Role `gorm:"size:20;not null" json:"role"`
|
||||
TypeAbo string `gorm:"type:varchar(35);default:demo" json:"type_abonnement"`
|
||||
ExpiredAt time.Time `json:"expired_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// Réglages d'alerte monitoring (admin uniquement) : chaque admin
|
||||
// configure son propre canal, aucune variable d'env globale — voir
|
||||
// internal/alerts et internal/profile (Get/SetAlertSettings).
|
||||
AlertDiscordWebhookURL *string `gorm:"size:500" json:"-"`
|
||||
AlertTelegramBotToken *string `gorm:"size:200" json:"-"`
|
||||
AlertTelegramChatID *string `gorm:"size:64" json:"-"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user