change session name

This commit is contained in:
mhsanaei 2024-07-05 14:33:04 +02:00
parent 24b9e5bfa3
commit 02ae61fe6b
4 changed files with 15 additions and 12 deletions

View File

@ -503,6 +503,7 @@
this.loading(false);
if (msg.success) {
this.user = {};
window.location.replace(basePath + "logout");
}
},
async restartPanel() {

View File

@ -9,9 +9,7 @@ import (
"github.com/gin-gonic/gin"
)
const (
loginUser = "LOGIN_USER"
)
const loginUser = "LOGIN_USER"
func init() {
gob.Register(model.User{})
@ -34,24 +32,28 @@ func SetMaxAge(c *gin.Context, maxAge int) error {
func GetLoginUser(c *gin.Context) *model.User {
s := sessions.Default(c)
obj := s.Get(loginUser)
if obj == nil {
return nil
}
user := obj.(model.User)
if obj := s.Get(loginUser); obj != nil {
if user, ok := obj.(model.User); ok {
return &user
}
}
return nil
}
func IsLogin(c *gin.Context) bool {
return GetLoginUser(c) != nil
}
func ClearSession(c *gin.Context) {
func ClearSession(c *gin.Context) error {
s := sessions.Default(c)
s.Clear()
s.Options(sessions.Options{
Path: "/",
MaxAge: -1,
})
s.Save()
if err := s.Save(); err != nil {
return err
}
c.SetCookie("3x-ui", "", -1, "/", "", false, true)
return nil
}

View File

@ -180,7 +180,7 @@ func (s *Server) initRouter() (*gin.Engine, error) {
assetsBasePath := basePath + "assets/"
store := cookie.NewStore(secret)
engine.Use(sessions.Sessions("session", store))
engine.Use(sessions.Sessions("3x-ui", store))
engine.Use(func(c *gin.Context) {
c.Set("base_path", basePath)
})