mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Add a 'Remember me' checkbox when logging in to save a session https://github.com/siyuan-note/siyuan/pull/14964
This commit is contained in:
parent
aa35dd827b
commit
f3fe90cbd8
13 changed files with 37 additions and 33 deletions
|
|
@ -27,11 +27,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
ginSessions "github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
ginSessions "github.com/gin-contrib/sessions"
|
||||
"github.com/steambap/captcha"
|
||||
)
|
||||
|
||||
|
|
@ -122,27 +122,20 @@ func LoginAuth(c *gin.Context) {
|
|||
workspaceSession.AccessAuthCode = authCode
|
||||
util.WrongAuthCount = 0
|
||||
workspaceSession.Captcha = gulu.Rand.String(7)
|
||||
|
||||
// Handle remember me preference
|
||||
if rememberMe, ok := arg["rememberMe"].(bool); ok && rememberMe {
|
||||
// Set session cookie to expire in 30 days
|
||||
ginSessions.Default(c).Options(ginSessions.Options{
|
||||
Path: "/",
|
||||
Secure: util.SSL,
|
||||
MaxAge: 30 * 24 * 60 * 60, // 30 days in seconds
|
||||
HttpOnly: true,
|
||||
})
|
||||
} else {
|
||||
// Default session expiration (browser session)
|
||||
ginSessions.Default(c).Options(ginSessions.Options{
|
||||
Path: "/",
|
||||
Secure: util.SSL,
|
||||
MaxAge: 0, // Session cookie
|
||||
HttpOnly: true,
|
||||
})
|
||||
}
|
||||
|
||||
logging.LogInfof("auth success [ip=%s]", util.GetRemoteAddr(c.Request))
|
||||
maxAge := 0 // Default session expiration (browser session)
|
||||
if rememberMe, ok := arg["rememberMe"].(bool); ok && rememberMe {
|
||||
// Add a 'Remember me' checkbox when logging in to save a session https://github.com/siyuan-note/siyuan/pull/14964
|
||||
maxAge = 60 * 60 * 24 * 30 // 30 days
|
||||
}
|
||||
ginSessions.Default(c).Options(ginSessions.Options{
|
||||
Path: "/",
|
||||
Secure: util.SSL,
|
||||
MaxAge: maxAge,
|
||||
HttpOnly: true,
|
||||
})
|
||||
|
||||
logging.LogInfof("auth success [ip=%s, maxAge=%d]", util.GetRemoteAddr(c.Request), maxAge)
|
||||
if err := session.Save(c); err != nil {
|
||||
logging.LogErrorf("save session failed: " + err.Error())
|
||||
c.Status(http.StatusInternalServerError)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue