1
0

feat: 合并Gin_Vue

This commit is contained in:
TsMask
2023-10-16 20:04:08 +08:00
parent 55fe1d534d
commit 05c7e9b9e8
213 changed files with 20338 additions and 311 deletions

View File

@@ -14,7 +14,6 @@ import (
sysConfigService "ems.agt/features/sys_config/service"
"ems.agt/lib/core/account"
"ems.agt/lib/core/cache"
"ems.agt/lib/core/conf"
"ems.agt/lib/core/constants/cachekey"
"ems.agt/lib/core/utils/ctx"
"ems.agt/lib/core/vo/result"
@@ -24,7 +23,8 @@ import (
"ems.agt/lib/oauth"
"ems.agt/lib/services"
"ems.agt/restagent/config"
"github.com/go-admin-team/go-admin-core/logger"
srcConfig "ems.agt/src/framework/config"
"ems.agt/src/framework/redis"
"github.com/mojocn/base64Captcha"
)
@@ -136,9 +136,10 @@ func LoginFromOMC(w http.ResponseWriter, r *http.Request) {
if user != nil {
// 缓存用户信息
account.CacheLoginUser(user)
redis.SetByExpire("", "session_token", token, time.Second*1800)
// 角色权限集合,管理员拥有所有权限
userId := fmt.Sprint(user.Id)
isAdmin := conf.IsAdmin(userId)
isAdmin := srcConfig.IsAdmin(userId)
roles, perms := service.NewServiceAccount.RoleAndMenuPerms(userId, isAdmin)
services.ResponseStatusOK200LoginWhitRP(w, token, user, roles, perms)
return
@@ -237,13 +238,13 @@ func LoginOMC(w http.ResponseWriter, r *http.Request) {
err := ctx.ShouldBindJSON(r, &body)
if err != nil {
log.Error("Invalid Json Format")
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// response 400-5
if body.Username == "" || body.Password == "" {
log.Error("Wrong parameter value")
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -257,20 +258,20 @@ func LoginOMC(w http.ResponseWriter, r *http.Request) {
if captchaEnabled {
if body.Code == "" || body.UUID == "" {
log.Error("Authentication failed, mismatch captcha")
ctx.JSON(w, 400, result.CodeMsg(400, "验证码信息错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "Verification code information error"))
return
}
verifyKey := cachekey.CAPTCHA_CODE_KEY + body.UUID
captcha, ok := cache.GetLocalTTL(verifyKey)
if captcha == nil || !ok {
log.Error("Authentication failed, captcha emtry")
ctx.JSON(w, 400, result.CodeMsg(400, "验证码已失效"))
ctx.JSON(w, 400, result.CodeMsg(400, "The verification code has expired"))
return
}
cache.DeleteLocalTTL(verifyKey)
if captcha.(string) != body.Code {
log.Error("Authentication failed, not match captcha")
ctx.JSON(w, 400, result.CodeMsg(400, "验证码错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "Verification code error"))
return
}
}
@@ -363,7 +364,7 @@ func CaptchaImage(w http.ResponseWriter, r *http.Request) {
// 验证码表达式解析输出
item, err := driverCaptcha.DrawCaptcha(question)
if err != nil {
logger.Infof("Generate Id Question Answer %s : %v", question, err)
log.Infof("Generate Id Question Answer %s : %v", question, err)
} else {
data["uuid"] = id
data["img"] = item.EncodeB64string()
@@ -388,7 +389,7 @@ func UserInfo(w http.ResponseWriter, r *http.Request) {
}
// 角色权限集合,管理员拥有所有权限
userId := fmt.Sprint(loginUser.UserID)
isAdmin := conf.IsAdmin(userId)
isAdmin := srcConfig.IsAdmin(userId)
roles, perms := service.NewServiceAccount.RoleAndMenuPerms(userId, isAdmin)
ctx.JSON(w, 200, result.OkData(map[string]any{
@@ -403,7 +404,7 @@ func Routers(w http.ResponseWriter, r *http.Request) {
userID := ctx.LoginUserToUserID(r)
// 前端路由,管理员拥有所有
isAdmin := conf.IsAdmin(userID)
isAdmin := srcConfig.IsAdmin(userID)
buildMenus := service.NewServiceAccount.RouteMenus(userID, isAdmin)
ctx.JSON(w, 200, result.OkData(buildMenus))
}