Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authormhsanaei <ho3ein.sanaei@gmail.com>2024-07-05 15:33:04 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2024-07-05 15:33:04 +0300
commit02ae61fe6beb68ab8e5859a5eaa2b68514c0b454 (patch)
tree16ba0c036275bad58ec5037623f819414874062d /web
parent24b9e5bfa377f32e0942fbc9a207864b55b20d4a (diff)
change session name
Diffstat (limited to 'web')
-rw-r--r--web/controller/index.go2
-rw-r--r--web/html/xui/settings.html1
-rw-r--r--web/session/session.go22
-rw-r--r--web/web.go2
4 files changed, 15 insertions, 12 deletions
diff --git a/web/controller/index.go b/web/controller/index.go
index f887062a..12a2d99c 100644
--- a/web/controller/index.go
+++ b/web/controller/index.go
@@ -94,7 +94,7 @@ func (a *IndexController) login(c *gin.Context) {
func (a *IndexController) logout(c *gin.Context) {
user := session.GetLoginUser(c)
if user != nil {
- logger.Info(user.Username, "logged out successfully")
+ logger.Info(user.Username, " logged out successfully")
}
session.ClearSession(c)
c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path"))
diff --git a/web/html/xui/settings.html b/web/html/xui/settings.html
index 96293daf..2c5c62a0 100644
--- a/web/html/xui/settings.html
+++ b/web/html/xui/settings.html
@@ -503,6 +503,7 @@
this.loading(false);
if (msg.success) {
this.user = {};
+ window.location.replace(basePath + "logout");
}
},
async restartPanel() {
diff --git a/web/session/session.go b/web/session/session.go
index df38fceb..2b8e994e 100644
--- a/web/session/session.go
+++ b/web/session/session.go
@@ -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
+ if obj := s.Get(loginUser); obj != nil {
+ if user, ok := obj.(model.User); ok {
+ return &user
+ }
}
- user := obj.(model.User)
- 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
}
diff --git a/web/web.go b/web/web.go
index c3d04ff9..dadbfda1 100644
--- a/web/web.go
+++ b/web/web.go
@@ -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)
})