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() +}