Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve auth

Danieleec003b3034f
diff --git a/kernel/model/session.go b/kernel/model/session.go
index e0fef0d033..c82c67580d 100644
--- a/kernel/model/session.go
+++ b/kernel/model/session.go
@@ -120,7 +120,9 @@ func LoginAuth(c *gin.Context) {
if err := session.Save(c); err != nil {
logging.LogErrorf("save session failed: " + err.Error())
- c.Status(http.StatusInternalServerError)
+ session.Clear(c)
+ ret.Code = 1
+ ret.Msg = Conf.Language(258)
return
}
return
diff --git a/kernel/util/session.go b/kernel/util/session.go
index 070742d9a0..32ff0b4454 100644
--- a/kernel/util/session.go
+++ b/kernel/util/session.go
@@ -20,6 +20,7 @@ import (
"github.com/88250/gulu"
ginSessions "github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
+ "github.com/siyuan-note/logging"
)
var WrongAuthCount int
@@ -38,6 +39,14 @@ type WorkspaceSession struct {
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.
func (sd *SessionData) Save(c *gin.Context) error {
session := ginSessions.Default(c)