mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-03-01 01:20:49 +03:00
change session name
This commit is contained in:
parent
24b9e5bfa3
commit
02ae61fe6b
@ -94,7 +94,7 @@ func (a *IndexController) login(c *gin.Context) {
|
|||||||
func (a *IndexController) logout(c *gin.Context) {
|
func (a *IndexController) logout(c *gin.Context) {
|
||||||
user := session.GetLoginUser(c)
|
user := session.GetLoginUser(c)
|
||||||
if user != nil {
|
if user != nil {
|
||||||
logger.Info(user.Username, "logged out successfully")
|
logger.Info(user.Username, " logged out successfully")
|
||||||
}
|
}
|
||||||
session.ClearSession(c)
|
session.ClearSession(c)
|
||||||
c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path"))
|
c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path"))
|
||||||
|
@ -503,6 +503,7 @@
|
|||||||
this.loading(false);
|
this.loading(false);
|
||||||
if (msg.success) {
|
if (msg.success) {
|
||||||
this.user = {};
|
this.user = {};
|
||||||
|
window.location.replace(basePath + "logout");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async restartPanel() {
|
async restartPanel() {
|
||||||
|
@ -9,9 +9,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const loginUser = "LOGIN_USER"
|
||||||
loginUser = "LOGIN_USER"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
gob.Register(model.User{})
|
gob.Register(model.User{})
|
||||||
@ -34,24 +32,28 @@ func SetMaxAge(c *gin.Context, maxAge int) error {
|
|||||||
|
|
||||||
func GetLoginUser(c *gin.Context) *model.User {
|
func GetLoginUser(c *gin.Context) *model.User {
|
||||||
s := sessions.Default(c)
|
s := sessions.Default(c)
|
||||||
obj := s.Get(loginUser)
|
if obj := s.Get(loginUser); obj != nil {
|
||||||
if obj == nil {
|
if user, ok := obj.(model.User); ok {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
user := obj.(model.User)
|
|
||||||
return &user
|
return &user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsLogin(c *gin.Context) bool {
|
func IsLogin(c *gin.Context) bool {
|
||||||
return GetLoginUser(c) != nil
|
return GetLoginUser(c) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClearSession(c *gin.Context) {
|
func ClearSession(c *gin.Context) error {
|
||||||
s := sessions.Default(c)
|
s := sessions.Default(c)
|
||||||
s.Clear()
|
s.Clear()
|
||||||
s.Options(sessions.Options{
|
s.Options(sessions.Options{
|
||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: -1,
|
MaxAge: -1,
|
||||||
})
|
})
|
||||||
s.Save()
|
if err := s.Save(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.SetCookie("3x-ui", "", -1, "/", "", false, true)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ func (s *Server) initRouter() (*gin.Engine, error) {
|
|||||||
assetsBasePath := basePath + "assets/"
|
assetsBasePath := basePath + "assets/"
|
||||||
|
|
||||||
store := cookie.NewStore(secret)
|
store := cookie.NewStore(secret)
|
||||||
engine.Use(sessions.Sessions("session", store))
|
engine.Use(sessions.Sessions("3x-ui", store))
|
||||||
engine.Use(func(c *gin.Context) {
|
engine.Use(func(c *gin.Context) {
|
||||||
c.Set("base_path", basePath)
|
c.Set("base_path", basePath)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user