This commit is contained in:
邹宗楠
2022-07-26 17:37:13 +08:00
parent d038f31e87
commit f4f6bbd80b
13 changed files with 123 additions and 121 deletions

View File

@@ -2,7 +2,6 @@ package controllers
import (
"encoding/json"
"git.rosy.net.cn/jx-print/controllers/controller"
"git.rosy.net.cn/jx-print/globals"
"git.rosy.net.cn/jx-print/model"
"git.rosy.net.cn/jx-print/putils"
@@ -36,7 +35,7 @@ func RegisterUser(c *gin.Context) {
globals.SugarLogger.Debugf("API :%s error:%v:", c.Request.URL, err)
return
}
if !controller.CaptchaVerify(c, user.Code) {
if !CaptchaVerify(c, user.Code) {
c.JSON(http.StatusOK, &model.CallBack{
Code: model.ErrCodeNormal,
Desc: "验证码错误!",
@@ -44,7 +43,7 @@ func RegisterUser(c *gin.Context) {
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
return
}
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
if !CallFunc(c, func() (retVal interface{}, errCode string, err error) {
err = print_server.RegisterUser(c, user.Name, user.Password)
return retVal, "", err
}) {
@@ -67,7 +66,7 @@ func Login(c *gin.Context) {
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
return
}
if !controller.CaptchaVerify(c, user.Code) {
if !CaptchaVerify(c, user.Code) {
c.JSON(http.StatusOK, &model.CallBack{
Code: model.ErrCodeNormal,
Desc: "验证码错误!",
@@ -75,9 +74,18 @@ func Login(c *gin.Context) {
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
return
}
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
retVal, err = print_server.Login(c, user.Name, user.Password)
return retVal, "", err
if !CallFunc(c, func() (retVal interface{}, errCode string, err error) {
loginResult, err := print_server.Login(c, user.Name, user.Password)
if err != nil {
return nil, "", err
}
//创建token
token, err := SetToken(&loginResult.User)
if err != nil {
return nil, "", err
}
loginResult.Token = token
return loginResult, "", err
}) {
return
}
@@ -89,7 +97,7 @@ func GetTokenInfo(c *gin.Context) {
var (
tokenInfo *model.TokenInfo
)
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
if tokenInfo = CheckToken(c); tokenInfo == nil {
return
}
data, _ := json.Marshal(tokenInfo)
@@ -105,10 +113,10 @@ func Logout(c *gin.Context) {
var (
tokenInfo *model.TokenInfo
)
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
if tokenInfo = CheckToken(c); tokenInfo == nil {
return
}
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
if !CallFunc(c, func() (retVal interface{}, errCode string, err error) {
err = print_server.Logout(c, tokenInfo.Token)
return retVal, "", err
}) {
@@ -133,10 +141,10 @@ func UpdateUser(c *gin.Context) {
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
return
}
if tokenInfo := controller.CheckToken(c); tokenInfo == nil {
if tokenInfo := CheckToken(c); tokenInfo == nil {
return
}
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
if !CallFunc(c, func() (retVal interface{}, errCode string, err error) {
err = print_server.UpdateUser(c, user.Payload)
return retVal, "", err
}) {
@@ -147,7 +155,7 @@ func UpdateUser(c *gin.Context) {
//获取菜单,文档 GET
func GetMenus(c *gin.Context) {
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
if !CallFunc(c, func() (retVal interface{}, errCode string, err error) {
retVal, err = print_server.GetMenus(c)
return retVal, "", err
}) {
@@ -172,7 +180,7 @@ func GetMenuDetail(c *gin.Context) {
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
return
}
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
if !CallFunc(c, func() (retVal interface{}, errCode string, err error) {
retVal, err = print_server.GetMenuDetail(c, user.ID)
return retVal, "", err
}) {