1
0

feat: 更新代码

This commit is contained in:
TsMask
2023-10-20 20:12:11 +08:00
parent bbdced9633
commit d63db9dd6c
14 changed files with 274 additions and 60 deletions

View File

@@ -16,7 +16,7 @@ func ErrorCatch() gin.HandlerFunc {
defer func() {
// 在这里处理 Panic 异常,例如记录日志或返回错误信息给客户端
if err := recover(); err != nil {
logger.Errorf("发生了 Panic 异常: %v", err)
logger.Errorf("Panic 异常: %s => %v", c.Request.URL, err)
// 返回错误响应给客户端
if config.Env() == "prod" {

View File

@@ -12,18 +12,19 @@ import (
// SessionToken 设置登录会话-兼容旧登录方式
func SessionToken(username, sourceAddr string) bool {
token, _ := redis.Get("", "session_token")
if token != "" {
se, err := dborm.XormUpdateSessionShakeTime(token)
if se.AccountId != username || err != nil {
// 过期时间单位秒 配置1800是半小时
expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second
redis.SetByExpire("", "session_token", token, expireTime)
return true
}
}
token = oauth.GenRandToken("omc") // Generate new token to session ID
// token, _ := redis.Get("", "session_token")
// if token != "" {
// se, err := dborm.XormUpdateSessionShakeTime(token)
// if se.AccountId != username || err != nil {
// // 过期时间单位秒 配置1800是半小时
// expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second
// redis.SetByExpire("", "session_token", token, expireTime)
// return true
// }
// }
// 不管原先的登录情况直接插入写入覆盖redis中session
//
token := oauth.GenRandToken("omc") // Generate new token to session ID
affected, err := dborm.XormInsertSession(username, sourceAddr, token, libConfig.GetExpiresFromConfig(), libConfig.GetYamlConfig().Auth.Session)
if err != nil {
logger.Errorf("SessionToken XormInsertSession err %v", err)

View File

@@ -1,8 +1,10 @@
package session
import (
"ems.agt/src/framework/redis"
"time"
libConfig "ems.agt/restagent/config"
"ems.agt/src/framework/redis"
"github.com/gin-gonic/gin"
)
@@ -11,7 +13,10 @@ func SessionHeader() gin.HandlerFunc {
return func(c *gin.Context) {
// 读取登录生成的会话token
token, err := redis.Get("", "session_token")
if err == nil {
if token != "" || err == nil {
// 过期时间单位秒 配置1800是半小时
expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second
redis.SetByExpire("", "session_token", token, expireTime)
c.Request.Header.Set("Accesstoken", token)
}

View File

@@ -134,7 +134,7 @@ func (s *AccountController) Logout(c *gin.Context) {
os, browser := ctxUtils.UaOsBrowser(c)
// 创建系统访问记录
s.sysLogLoginService.NewSysLogLogin(
userName, commonConstants.STATUS_NO, "退出成功",
userName, commonConstants.STATUS_YES, "退出成功",
ipaddr, location, os, browser,
)
}

View File

@@ -79,7 +79,7 @@ func (s *SysMenuController) Add(c *gin.Context) {
// 目录和菜单检查地址唯一
if menu.TYPE_DIR == body.MenuType || menu.TYPE_MENU == body.MenuType {
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, "")
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.ParentID, "")
if !uniqueNenuPath {
msg := fmt.Sprintf("菜单新增【%s】失败菜单路由地址已存在", body.MenuName)
c.JSON(200, result.ErrMsg(msg))
@@ -151,7 +151,7 @@ func (s *SysMenuController) Edit(c *gin.Context) {
// 目录和菜单检查地址唯一
if menu.TYPE_DIR == body.MenuType || menu.TYPE_MENU == body.MenuType {
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.MenuID)
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.ParentID, body.MenuID)
if !uniqueNenuPath {
msg := fmt.Sprintf("菜单修改【%s】失败菜单路由地址已存在", body.MenuName)
c.JSON(200, result.ErrMsg(msg))

View File

@@ -44,7 +44,7 @@ type ISysMenu interface {
CheckUniqueMenuName(menuName, parentId, menuId string) bool
// CheckUniqueMenuPath 校验路由地址是否唯一(针对目录和菜单)
CheckUniqueMenuPath(path, menuId string) bool
CheckUniqueMenuPath(path, parentId, menuId string) bool
// BuildRouteMenus 构建前端路由所需要的菜单
BuildRouteMenus(sysMenus []model.SysMenu, prefix string) []vo.Router

View File

@@ -124,9 +124,10 @@ func (r *SysMenuImpl) CheckUniqueMenuName(menuName, parentId, menuId string) boo
}
// CheckUniqueMenuPath 校验路由地址是否唯一(针对目录和菜单)
func (r *SysMenuImpl) CheckUniqueMenuPath(path, menuId string) bool {
func (r *SysMenuImpl) CheckUniqueMenuPath(path, parentId, menuId string) bool {
uniqueId := r.sysMenuRepository.CheckUniqueMenu(model.SysMenu{
Path: path,
Path: path,
ParentID: parentId,
})
if uniqueId == menuId {
return true