fix: 用户名或密码修改,将所有登录都退出

This commit is contained in:
ssongliu 2023-03-11 11:33:21 +08:00 committed by ssongliu
parent 252c48bb40
commit 76a0c38327
3 changed files with 16 additions and 10 deletions

View File

@ -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
}

View File

@ -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 {

View File

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