FEATURE: Add support for not persistent sessions
In some cases Discourse admins may opt for sessions not to persist when a browser is closed. This is particularly useful in healthcare and education settings where computers are shared among multiple workers. By default `persistent_sessions` site setting is enabled, to opt out you must disable the site setting.
This commit is contained in:
parent
9e4ed03b8f
commit
44fba9463b
|
@ -1543,6 +1543,7 @@ en:
|
||||||
invite_code: "User must type this code to be allowed account registration, ignored when empty (case-insensitive)"
|
invite_code: "User must type this code to be allowed account registration, ignored when empty (case-insensitive)"
|
||||||
approve_suspect_users: "Add suspicious users to the review queue. Suspicious users have entered a bio/website but have no reading activity."
|
approve_suspect_users: "Add suspicious users to the review queue. Suspicious users have entered a bio/website but have no reading activity."
|
||||||
pending_users_reminder_delay: "Notify moderators if new users have been waiting for approval for longer than this many hours. Set to -1 to disable notifications."
|
pending_users_reminder_delay: "Notify moderators if new users have been waiting for approval for longer than this many hours. Set to -1 to disable notifications."
|
||||||
|
persistent_sessions: "Users will remain logged in when the web browser is closed"
|
||||||
maximum_session_age: "User will remain logged in for n hours since last visit"
|
maximum_session_age: "User will remain logged in for n hours since last visit"
|
||||||
ga_universal_tracking_code: "Google Universal Analytics (analytics.js) tracking code ID, eg: UA-12345678-9; see <a href='https://google.com/analytics' target='_blank'>https://google.com/analytics</a>"
|
ga_universal_tracking_code: "Google Universal Analytics (analytics.js) tracking code ID, eg: UA-12345678-9; see <a href='https://google.com/analytics' target='_blank'>https://google.com/analytics</a>"
|
||||||
ga_universal_domain_name: "Google Universal Analytics (analytics.js) domain name, eg: mysite.com; see <a href='https://google.com/analytics' target='_blank'>https://google.com/analytics</a>"
|
ga_universal_domain_name: "Google Universal Analytics (analytics.js) domain name, eg: mysite.com; see <a href='https://google.com/analytics' target='_blank'>https://google.com/analytics</a>"
|
||||||
|
|
|
@ -478,6 +478,7 @@ login:
|
||||||
pending_users_reminder_delay:
|
pending_users_reminder_delay:
|
||||||
min: -1
|
min: -1
|
||||||
default: 8
|
default: 8
|
||||||
|
persistent_sessions: true
|
||||||
maximum_session_age:
|
maximum_session_age:
|
||||||
default: 1440
|
default: 1440
|
||||||
min: 1
|
min: 1
|
||||||
|
|
|
@ -224,10 +224,13 @@ class Auth::DefaultCurrentUserProvider
|
||||||
hash = {
|
hash = {
|
||||||
value: unhashed_auth_token,
|
value: unhashed_auth_token,
|
||||||
httponly: true,
|
httponly: true,
|
||||||
expires: SiteSetting.maximum_session_age.hours.from_now,
|
|
||||||
secure: SiteSetting.force_https
|
secure: SiteSetting.force_https
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if SiteSetting.persistent_sessions
|
||||||
|
hash[:expires] = SiteSetting.maximum_session_age.hours.from_now
|
||||||
|
end
|
||||||
|
|
||||||
if SiteSetting.same_site_cookies != "Disabled"
|
if SiteSetting.same_site_cookies != "Disabled"
|
||||||
hash[:same_site] = SiteSetting.same_site_cookies
|
hash[:same_site] = SiteSetting.same_site_cookies
|
||||||
end
|
end
|
||||||
|
|
|
@ -323,6 +323,16 @@ describe Auth::DefaultCurrentUserProvider do
|
||||||
expect(provider("/topic/anything/goes", params.merge("HTTP_DISCOURSE_PRESENT" => "true")).should_update_last_seen?).to eq(true)
|
expect(provider("/topic/anything/goes", params.merge("HTTP_DISCOURSE_PRESENT" => "true")).should_update_last_seen?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "supports non persistent sessions" do
|
||||||
|
SiteSetting.persistent_sessions = false
|
||||||
|
|
||||||
|
@provider = provider('/')
|
||||||
|
cookies = {}
|
||||||
|
@provider.log_on_user(user, {}, cookies)
|
||||||
|
|
||||||
|
expect(cookies["_t"][:expires]).to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
it "correctly rotates tokens" do
|
it "correctly rotates tokens" do
|
||||||
SiteSetting.maximum_session_age = 3
|
SiteSetting.maximum_session_age = 3
|
||||||
@provider = provider('/')
|
@provider = provider('/')
|
||||||
|
|
Loading…
Reference in New Issue