mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Add a 'remember me' checkbox when logging in to save a session for 30 days (#14964)
This commit is contained in:
parent
dae6158860
commit
aa35dd827b
4 changed files with 30 additions and 1 deletions
|
@ -1596,6 +1596,7 @@
|
||||||
"253": "Compressing file [%s], please wait...",
|
"253": "Compressing file [%s], please wait...",
|
||||||
"254": "[Region ID] Incorrect Region ID, please refer to the S3 service provider's documentation to configure the Region ID",
|
"254": "[Region ID] Incorrect Region ID, please refer to the S3 service provider's documentation to configure the Region ID",
|
||||||
"255": "The target site has enabled hotlink protection, so it is not possible to download [%d] resources",
|
"255": "The target site has enabled hotlink protection, so it is not possible to download [%d] resources",
|
||||||
"256": "The specified path [%s] has a parent workspace path [%s]"
|
"256": "The specified path [%s] has a parent workspace path [%s]",
|
||||||
|
"257": "Remember me for 30 days"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,10 @@
|
||||||
<img id="captchaImg" style="top: 1px;position: absolute;height: 26px;right: 1px;cursor: pointer">
|
<img id="captchaImg" style="top: 1px;position: absolute;height: 26px;right: 1px;cursor: pointer">
|
||||||
<input id="captcha" class="b3-text-field" placeholder="{{.l3}}">
|
<input id="captcha" class="b3-text-field" placeholder="{{.l3}}">
|
||||||
</div>
|
</div>
|
||||||
|
<div style="width: 240px; margin: 8px auto; text-align: left;">
|
||||||
|
<input type="checkbox" id="rememberMe" style="margin-right: 8px;">
|
||||||
|
<label for="rememberMe" style="color: var(--b3-theme-on-surface); font-size: 14px;">{{.l10}}</label>
|
||||||
|
</div>
|
||||||
<button class="b3-button" onclick="submitAuth()">{{.l1}}</button>
|
<button class="b3-button" onclick="submitAuth()">{{.l1}}</button>
|
||||||
<div class="ft__on-surface">
|
<div class="ft__on-surface">
|
||||||
{{.l2}}
|
{{.l2}}
|
||||||
|
@ -475,6 +479,7 @@
|
||||||
const submitAuth = () => {
|
const submitAuth = () => {
|
||||||
const inputElement = document.getElementById('authCode')
|
const inputElement = document.getElementById('authCode')
|
||||||
const captchaElement = document.getElementById('captcha')
|
const captchaElement = document.getElementById('captcha')
|
||||||
|
const rememberMeElement = document.getElementById('rememberMe')
|
||||||
let code = inputElement.value.trim();
|
let code = inputElement.value.trim();
|
||||||
if ("" === code) {
|
if ("" === code) {
|
||||||
showMessage({{.l9}})
|
showMessage({{.l9}})
|
||||||
|
@ -489,6 +494,7 @@
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
authCode: code,
|
authCode: code,
|
||||||
captcha: captchaElement.value,
|
captcha: captchaElement.value,
|
||||||
|
rememberMe: rememberMeElement.checked
|
||||||
}),
|
}),
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
|
ginSessions "github.com/gin-contrib/sessions"
|
||||||
"github.com/steambap/captcha"
|
"github.com/steambap/captcha"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -121,6 +122,26 @@ func LoginAuth(c *gin.Context) {
|
||||||
workspaceSession.AccessAuthCode = authCode
|
workspaceSession.AccessAuthCode = authCode
|
||||||
util.WrongAuthCount = 0
|
util.WrongAuthCount = 0
|
||||||
workspaceSession.Captcha = gulu.Rand.String(7)
|
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))
|
logging.LogInfof("auth success [ip=%s]", util.GetRemoteAddr(c.Request))
|
||||||
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())
|
||||||
|
|
|
@ -452,6 +452,7 @@ func serveAuthPage(c *gin.Context) {
|
||||||
"l7": template.HTML(model.Conf.Language(184)),
|
"l7": template.HTML(model.Conf.Language(184)),
|
||||||
"l8": model.Conf.Language(95),
|
"l8": model.Conf.Language(95),
|
||||||
"l9": model.Conf.Language(83),
|
"l9": model.Conf.Language(83),
|
||||||
|
"l10": model.Conf.Language(257),
|
||||||
"appearanceMode": model.Conf.Appearance.Mode,
|
"appearanceMode": model.Conf.Appearance.Mode,
|
||||||
"appearanceModeOS": model.Conf.Appearance.ModeOS,
|
"appearanceModeOS": model.Conf.Appearance.ModeOS,
|
||||||
"workspace": util.WorkspaceName,
|
"workspace": util.WorkspaceName,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue