feat: delete useless

This commit is contained in:
engigu
2024-01-01 13:09:44 +08:00
parent 965ea46643
commit d8f8927c7c
14 changed files with 44 additions and 193 deletions
+17 -29
View File
@@ -1,9 +1,9 @@
package api
import (
"fmt"
"net/http"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"message-nest/pkg/app"
@@ -18,52 +18,40 @@ type auth struct {
}
type ReqAuth struct {
Username string `json:"username"`
Password string `json:"passwd"`
Username string `json:"username" validate:"required,max=36" label:"用户名"`
Password string `json:"passwd" validate:"required,max=36" label:"密码"`
}
func GetAuth(c *gin.Context) {
appG := app.Gin{C: c}
valid := validation.Validation{}
var user ReqAuth
err := c.ShouldBindJSON(&user)
if err != nil {
app.MarkErrors(valid.Errors)
appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
return
}
username := user.Username
password := user.Password
a := auth{Username: username, Password: password}
ok, _ := valid.Valid(&a)
if !ok {
app.MarkErrors(valid.Errors)
appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
var (
appG = app.Gin{C: c}
req ReqAuth
)
add
errCode, errMsg := app.BindJsonAndPlayValid(c, &req)
if errCode != e.SUCCESS {
appG.CResponse(errCode, errMsg, nil)
return
}
authService := auth_service.Auth{Username: username, Password: password}
authService := auth_service.Auth{Username: req.Username, Password: req.Password}
isExist, err := authService.Check()
if err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_CHECK_TOKEN_FAIL, nil)
appG.CResponse(http.StatusInternalServerError, fmt.Sprintf("校验失败:%s", err), nil)
return
}
if !isExist {
appG.Response(http.StatusUnauthorized, e.ERROR_AUTH, nil)
appG.CResponse(http.StatusUnauthorized, "账号或密码不正确!", nil)
return
}
token, err := util.GenerateToken(username, password)
token, err := util.GenerateToken(req.Username, req.Password)
if err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_TOKEN, nil)
appG.CResponse(http.StatusInternalServerError, fmt.Sprintf("生成token失败:%s", err), nil)
return
}
appG.Response(http.StatusOK, e.SUCCESS, map[string]string{
appG.CResponse(http.StatusOK, "登录成功!", map[string]string{
"token": token,
})
}