mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: detect when client thinks user is logged on but is not
This cleans up an error condition where UI thinks a user is logged on but the user is not. If this happens user will be prompted to refresh.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
// Stuff we need to load first
|
||||
//= require ./discourse/lib/utilities
|
||||
//= require ./discourse/lib/page-visible
|
||||
//= require ./discourse/lib/logout
|
||||
//= require ./discourse/lib/ajax
|
||||
//= require ./discourse/lib/text
|
||||
//= require ./discourse/lib/hash
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import logout from 'discourse/lib/logout';
|
||||
|
||||
let _showingLogout = false;
|
||||
|
||||
// Subscribe to "logout" change events via the Message Bus
|
||||
export default {
|
||||
name: "logout",
|
||||
@@ -7,14 +9,22 @@ export default {
|
||||
|
||||
initialize: function (container) {
|
||||
const messageBus = container.lookup('message-bus:main');
|
||||
const siteSettings = container.lookup('site-settings:main');
|
||||
const keyValueStore = container.lookup('key-value-store:main');
|
||||
|
||||
if (!messageBus) { return; }
|
||||
const callback = () => logout(siteSettings, keyValueStore);
|
||||
|
||||
messageBus.subscribe("/logout", function () {
|
||||
bootbox.dialog(I18n.t("logout"), {label: I18n.t("refresh"), callback}, {onEscape: callback, backdrop: 'static'});
|
||||
if (!_showingLogout) {
|
||||
|
||||
_showingLogout = true;
|
||||
|
||||
bootbox.dialog(I18n.t("logout"), {
|
||||
label: I18n.t("refresh"),
|
||||
callback: logout
|
||||
}, {
|
||||
onEscape: logout,
|
||||
backdrop: 'static'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import pageVisible from 'discourse/lib/page-visible';
|
||||
import logout from 'discourse/lib/logout';
|
||||
|
||||
let _trackView = false;
|
||||
let _transientHeader = null;
|
||||
let _showingLogout = false;
|
||||
|
||||
export function setTransientHeader(key, value) {
|
||||
_transientHeader = {key, value};
|
||||
@@ -39,6 +41,10 @@ export function ajax() {
|
||||
|
||||
args.headers = args.headers || {};
|
||||
|
||||
if (Discourse.__container__.lookup('current-user:main')) {
|
||||
args.headers['Discourse-Logged-In'] = "true";
|
||||
}
|
||||
|
||||
if (_transientHeader) {
|
||||
args.headers[_transientHeader.key] = _transientHeader.value;
|
||||
_transientHeader = null;
|
||||
@@ -54,7 +60,22 @@ export function ajax() {
|
||||
args.headers['Discourse-Visible'] = "true";
|
||||
}
|
||||
|
||||
let handleLogoff = function(xhr) {
|
||||
if (xhr.getResponseHeader('Discourse-Logged-Out') && !_showingLogout) {
|
||||
_showingLogout = true;
|
||||
bootbox.dialog(
|
||||
I18n.t("logout"), {label: I18n.t("refresh"), callback: logout},
|
||||
{
|
||||
onEscape: () => logout(),
|
||||
backdrop: 'static'
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
args.success = (data, textStatus, xhr) => {
|
||||
handleLogoff(xhr);
|
||||
|
||||
if (xhr.getResponseHeader('Discourse-Readonly')) {
|
||||
Ember.run(() => Discourse.Site.currentProp('isReadOnly', true));
|
||||
}
|
||||
@@ -67,6 +88,8 @@ export function ajax() {
|
||||
};
|
||||
|
||||
args.error = (xhr, textStatus, errorThrown) => {
|
||||
handleLogoff(xhr);
|
||||
|
||||
// note: for bad CSRF we don't loop an extra request right away.
|
||||
// this allows us to eliminate the possibility of having a loop.
|
||||
if (xhr.status === 403 && xhr.responseText === "[\"BAD CSRF\"]") {
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
export default function logout(siteSettings, keyValueStore) {
|
||||
if (!siteSettings || !keyValueStore) {
|
||||
const container = Discourse.__container__;
|
||||
siteSettings = siteSettings || container.lookup('site-settings:main');
|
||||
keyValueStore = keyValueStore || container.lookup('key-value-store:main');
|
||||
}
|
||||
|
||||
keyValueStore.abandonLocal();
|
||||
|
||||
const redirect = siteSettings.logout_redirect;
|
||||
|
||||
Reference in New Issue
Block a user