Skip to content

Commit 46d6fbf

Browse files
committed
🎨 Add a 'Remember me' checkbox when logging in to save a session #14964 #13147
1 parent f3fe90c commit 46d6fbf

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

kernel/model/session.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ func LoginAuth(c *gin.Context) {
9292
ret.Code = 1
9393
ret.Msg = Conf.Language(22)
9494
logging.LogWarnf("invalid captcha")
95+
96+
workspaceSession.Captcha = gulu.Rand.String(7) // https://github.com/siyuan-note/siyuan/issues/13147
97+
if err := session.Save(c); err != nil {
98+
logging.LogErrorf("save session failed: " + err.Error())
99+
c.Status(http.StatusInternalServerError)
100+
return
101+
}
95102
return
96103
}
97104
}

kernel/server/serve.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/emersion/go-webdav/carddav"
3737
"github.com/gin-contrib/gzip"
3838
"github.com/gin-contrib/sessions"
39-
"github.com/gin-contrib/sessions/memstore"
39+
"github.com/gin-contrib/sessions/cookie"
4040
"github.com/gin-gonic/gin"
4141
"github.com/mssola/useragent"
4242
"github.com/olahol/melody"
@@ -61,8 +61,7 @@ const (
6161
)
6262

6363
var (
64-
// 这里用的是内存存储,意味着重启后所有 session 会丢失,需要重新登录
65-
sessionStore = memstore.NewStore([]byte("ATN51UlxVq1Gcvdf"))
64+
sessionStore = cookie.NewStore([]byte("ATN51UlxVq1Gcvdf"))
6665

6766
HttpMethods = []string{
6867
http.MethodGet,

0 commit comments

Comments
 (0)