修改重定向

pull/79/head^2
zhangchenhao 2025-05-08 15:43:14 +08:00
parent 375e4a55b3
commit 28dfd41249
1 changed files with 13 additions and 6 deletions

View File

@ -28,12 +28,14 @@ func SessionAuthMiddleware() gin.HandlerFunc {
gob.Register(time.Time{})
last := session.Get("lastRequestTime")
if routePath == public.Secure && session.Get("secure") == nil {
if routePath == public.Secure {
if session.Get("secure") == nil {
// 访问安全入口,设置 session
session.Set("secure", true)
session.Set("lastRequestTime", now)
// 一定要保存 session BEFORE redirect
session.Save()
}
// 返回登录页
c.Redirect(http.StatusFound, "/login")
// c.Abort()
@ -94,6 +96,11 @@ func SessionAuthMiddleware() gin.HandlerFunc {
// 访问正常,更新最后请求时间
session.Set("lastRequestTime", now)
session.Save()
if paths[0] == "login" {
c.Redirect(http.StatusFound, "/home")
c.Abort()
return
}
}
}
}