feat: 更新代码
This commit is contained in:
@@ -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" {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user