package system import ( "github.com/gin-gonic/gin" "net/http" systemmodel "gin-admin/internal/model/system" systemservice "gin-admin/internal/service/system" ) // @Author: yv1ing // @Author: me@yvling.cn // @Date: 2025/8/28 16:29 // @Desc: 系统用户服务接口 type SysUserLoginReq struct { Username string `json:"username"` Password string `json:"password"` } func SysUserLoginHandler(ctx *gin.Context) { var req SysUserLoginReq err := ctx.ShouldBindJSON(&req) if err != nil { ctx.AbortWithStatusJSON(http.StatusBadRequest, systemmodel.Response{ Code: http.StatusBadRequest, Info: "请求参数非法", }) return } jwtToken, err := systemservice.SysUserLogin(req.Username, req.Password) if err != nil { ctx.AbortWithStatusJSON(http.StatusInternalServerError, systemmodel.Response{ Code: http.StatusInternalServerError, Info: "登录请求失败:" + err.Error(), }) return } if jwtToken == "" { ctx.AbortWithStatusJSON(http.StatusForbidden, systemmodel.Response{ Code: http.StatusForbidden, Info: "登录请求失败:账号或密码错误", }) return } else { ctx.AbortWithStatusJSON(http.StatusOK, systemmodel.Response{ Code: http.StatusOK, Info: "登录请求成功", Data: gin.H{ "token": jwtToken, }, }) return } }