mirror of
https://github.com/yv1ing/gin-admin.git
synced 2025-10-24 10:12:05 +08:00
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package system
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
|
|
systemmodel "gin-admin/internal/model/system"
|
|
systemservice "gin-admin/internal/service/system"
|
|
)
|
|
|
|
// @Author: yv1ing
|
|
// @Email: 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
|
|
}
|
|
}
|