Re-migrate code

This commit is contained in:
2026-03-02 10:41:43 +08:00
parent 1cc3097d9b
commit 6070df659a
6 changed files with 139 additions and 29 deletions

View File

@@ -34,27 +34,19 @@ func NewAuthController() *AuthController {
// @Router /auth/login [post]
func (c *AuthController) Login(ctx *gin.Context) {
var loginData models.LoginDTO
if err := ctx.ShouldBindJSON(&loginData); err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "无效的请求数据",
"error": err.Error(),
})
if !BindJSON(ctx, &loginData) {
return
}
user, err := c.authService.ValidateUser(loginData.Username, loginData.Password)
if err != nil {
ctx.JSON(http.StatusUnauthorized, gin.H{
"message": err.Error(),
})
ErrorResponse(ctx, http.StatusUnauthorized, err.Error())
return
}
token, err := c.authService.GenerateToken(user)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{
"message": "令牌生成失败",
})
ErrorResponse(ctx, http.StatusInternalServerError, "令牌生成失败")
return
}