From 76a0c383273e8378ca6babe6da20b07e91faeea6 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Sat, 11 Mar 2023 11:33:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E5=90=8D=E6=88=96?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=B0=86=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=99=BB=E5=BD=95=E9=83=BD=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/setting.go | 12 ++++-------- backend/init/cache/badger_db/badger_db.go | 7 ++++++- backend/init/session/psession/psession.go | 7 ++++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go index 332960c7b..93ef774d5 100644 --- a/backend/app/service/setting.go +++ b/backend/app/service/setting.go @@ -60,6 +60,9 @@ func (u *SettingService) Update(key, value string) error { if err := settingRepo.Update(key, value); err != nil { return err } + if key == "UserName" { + _ = global.SESSION.Clean() + } return nil } @@ -115,13 +118,6 @@ func (u *SettingService) UpdatePassword(c *gin.Context, old, new string) error { if err := u.HandlePasswordExpired(c, old, new); err != nil { return err } - sID, _ := c.Cookie(constant.SessionName) - if sID != "" { - c.SetCookie(constant.SessionName, sID, -1, "", "", false, false) - err := global.SESSION.Delete(sID) - if err != nil { - return err - } - } + _ = global.SESSION.Clean() return nil } diff --git a/backend/init/cache/badger_db/badger_db.go b/backend/init/cache/badger_db/badger_db.go index 46588e336..069859e37 100644 --- a/backend/init/cache/badger_db/badger_db.go +++ b/backend/init/cache/badger_db/badger_db.go @@ -2,9 +2,10 @@ package badger_db import ( "fmt" + "time" + "github.com/dgraph-io/badger/v3" "github.com/pkg/errors" - "time" ) type Cache struct { @@ -44,6 +45,10 @@ func (c *Cache) Del(key string) error { return err } +func (c *Cache) Clean() error { + return c.db.DropAll() +} + func (c *Cache) Get(key string) ([]byte, error) { var result []byte err := c.db.View(func(txn *badger.Txn) error { diff --git a/backend/init/session/psession/psession.go b/backend/init/session/psession/psession.go index 5cf8ff0af..90cff7d5e 100644 --- a/backend/init/session/psession/psession.go +++ b/backend/init/session/psession/psession.go @@ -2,8 +2,9 @@ package psession import ( "encoding/json" - "github.com/1Panel-dev/1Panel/backend/init/cache/badger_db" "time" + + "github.com/1Panel-dev/1Panel/backend/init/cache/badger_db" ) type SessionUser struct { @@ -40,3 +41,7 @@ func (p *PSession) Set(sessionID string, user SessionUser, ttlSeconds int) error func (p *PSession) Delete(sessionID string) error { return p.store.Del(sessionID) } + +func (p *PSession) Clean() error { + return p.store.Clean() +}