From f394d3a8bda381ce03a98aafacee74f1d2ce9b73 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Thu, 28 May 2026 09:30:31 +0800 Subject: [PATCH] feat: add employee role and block backend login --- controllers/auth_controller.go | 4 ++++ models/models.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/controllers/auth_controller.go b/controllers/auth_controller.go index 59afaf4..154e83e 100644 --- a/controllers/auth_controller.go +++ b/controllers/auth_controller.go @@ -43,6 +43,10 @@ func (c *AuthController) Login(ctx *gin.Context) { ErrorResponse(ctx, http.StatusUnauthorized, err.Error()) return } + if user.Role == "employee" { + ErrorResponse(ctx, http.StatusForbidden, "员工账号无后台登录权限") + return + } token, err := c.authService.GenerateToken(user) if err != nil { diff --git a/models/models.go b/models/models.go index eb97cd2..3200d4a 100644 --- a/models/models.go +++ b/models/models.go @@ -80,14 +80,14 @@ type CreateUserDTO struct { Password string `json:"password" validate:"required,min=6"` Name string `json:"name" validate:"required"` Email string `json:"email" validate:"omitempty,email"` - Role string `json:"role" validate:"required,oneof=admin technician user"` + Role string `json:"role" validate:"required,oneof=admin technician employee user"` } // UpdateUserDTO 管理员更新用户信息请求 type UpdateUserDTO struct { Name string `json:"name,omitempty"` Email string `json:"email,omitempty" validate:"omitempty,email"` - Role string `json:"role,omitempty" validate:"omitempty,oneof=admin technician user"` + Role string `json:"role,omitempty" validate:"omitempty,oneof=admin technician employee user"` } // AdminResetPasswordDTO 管理员重置用户密码