🎨 Improve auth

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-11-21 10:18:59 +08:00
parent 67c7dd1e06
commit eec003b303
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 12 additions and 1 deletions

View file

@ -120,7 +120,9 @@ func LoginAuth(c *gin.Context) {
if err := session.Save(c); err != nil { if err := session.Save(c); err != nil {
logging.LogErrorf("save session failed: " + err.Error()) logging.LogErrorf("save session failed: " + err.Error())
c.Status(http.StatusInternalServerError) session.Clear(c)
ret.Code = 1
ret.Msg = Conf.Language(258)
return return
} }
return return

View file

@ -20,6 +20,7 @@ import (
"github.com/88250/gulu" "github.com/88250/gulu"
ginSessions "github.com/gin-contrib/sessions" ginSessions "github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/siyuan-note/logging"
) )
var WrongAuthCount int var WrongAuthCount int
@ -38,6 +39,14 @@ type WorkspaceSession struct {
Captcha string Captcha string
} }
func (sd *SessionData) Clear(c *gin.Context) {
session := ginSessions.Default(c)
session.Delete("data")
if err := session.Save(); err != nil {
logging.LogErrorf("clear session failed: %v", err)
}
}
// Save saves the current session of the specified context. // Save saves the current session of the specified context.
func (sd *SessionData) Save(c *gin.Context) error { func (sd *SessionData) Save(c *gin.Context) error {
session := ginSessions.Default(c) session := ginSessions.Default(c)