Avoid calling `Discourse.logout` and use an action instead
This commit is contained in:
parent
da25abfcc9
commit
11b73e1fb7
|
@ -78,26 +78,6 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
|||
this.set('notifyCount', count);
|
||||
},
|
||||
|
||||
/**
|
||||
Log the current user out of Discourse
|
||||
|
||||
@method logout
|
||||
**/
|
||||
logout: function() {
|
||||
Discourse.User.logout().then(function() {
|
||||
// Reloading will refresh unbound properties
|
||||
Discourse.KeyValueStore.abandonLocal();
|
||||
|
||||
var redirect = Discourse.SiteSettings.logout_redirect;
|
||||
if(redirect.length === 0){
|
||||
window.location.pathname = Discourse.getURL('/');
|
||||
} else {
|
||||
window.location.href = redirect;
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
authenticationComplete: function(options) {
|
||||
// TODO, how to dispatch this to the controller without the container?
|
||||
var loginController = Discourse.__container__.lookup('controller:login');
|
||||
|
|
|
@ -71,7 +71,7 @@ export default Ember.Component.extend({
|
|||
});
|
||||
},
|
||||
logout() {
|
||||
Discourse.logout();
|
||||
this.sendAction('logoutAction');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import logout from 'discourse/lib/logout';
|
||||
|
||||
// Subscribe to "logout" change events via the Message Bus
|
||||
export default {
|
||||
name: "logout",
|
||||
|
@ -8,17 +10,10 @@ export default {
|
|||
siteSettings = container.lookup('site-settings:main');
|
||||
|
||||
if (!messageBus) { return; }
|
||||
const callback = () => logout(siteSettings);
|
||||
|
||||
messageBus.subscribe("/logout", function () {
|
||||
var refresher = function() {
|
||||
var redirect = siteSettings.logout_redirect;
|
||||
if(redirect.length === 0){
|
||||
window.location.pathname = Discourse.getURL('/');
|
||||
} else {
|
||||
window.location.href = redirect;
|
||||
}
|
||||
};
|
||||
bootbox.dialog(I18n.t("logout"), {label: I18n.t("refresh"), callback: refresher}, {onEscape: refresher, backdrop: 'static'});
|
||||
bootbox.dialog(I18n.t("logout"), {label: I18n.t("refresh"), callback}, {onEscape: callback, backdrop: 'static'});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
|
||||
|
||||
var safeLocalStorage;
|
||||
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
export default function logout(siteSettings) {
|
||||
Discourse.KeyValueStore.abandonLocal();
|
||||
|
||||
const redirect = siteSettings.logout_redirect;
|
||||
if (Ember.isEmpty(redirect)) {
|
||||
window.location.pathname = Discourse.getURL('/');
|
||||
} else {
|
||||
window.location.href = redirect;
|
||||
}
|
||||
}
|
|
@ -26,14 +26,12 @@ const User = RestModel.extend({
|
|||
return UserPostsStream.create({ user: this });
|
||||
}.property(),
|
||||
|
||||
/**
|
||||
Is this user a member of staff?
|
||||
|
||||
@property staff
|
||||
@type {Boolean}
|
||||
**/
|
||||
staff: Em.computed.or('admin', 'moderator'),
|
||||
|
||||
destroySession() {
|
||||
return Discourse.ajax(`/session/${this.get('username')}`, { type: 'DELETE'});
|
||||
},
|
||||
|
||||
searchContext: function() {
|
||||
return {
|
||||
type: 'user',
|
||||
|
@ -449,21 +447,6 @@ User.reopenClass(Singleton, {
|
|||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
Logs out the currently logged in user
|
||||
|
||||
@method logout
|
||||
@returns {Promise} resolved when the logout finishes
|
||||
**/
|
||||
logout: function() {
|
||||
var discourseUserClass = this;
|
||||
return Discourse.ajax("/session/" + Discourse.User.currentProp('username'), {
|
||||
type: 'DELETE'
|
||||
}).then(function () {
|
||||
discourseUserClass.currentUser = null;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Checks if given username is valid for this email address
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { setting } from 'discourse/lib/computed';
|
||||
import logout from 'discourse/lib/logout';
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
import OpenComposer from "discourse/mixins/open-composer";
|
||||
|
||||
|
@ -16,6 +17,11 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
|||
siteTitle: setting('title'),
|
||||
|
||||
actions: {
|
||||
|
||||
logout() {
|
||||
this.currentUser.destroySession().then(() => logout(this.siteSettings));
|
||||
},
|
||||
|
||||
_collectTitleTokens(tokens) {
|
||||
tokens.push(this.get('siteTitle'));
|
||||
Discourse.set('_docTitle', tokens.join(' - '));
|
||||
|
|
|
@ -11,10 +11,6 @@ export default Discourse.Route.extend({
|
|||
},
|
||||
|
||||
actions: {
|
||||
logout() {
|
||||
Discourse.logout();
|
||||
},
|
||||
|
||||
composePrivateMessage(user, post) {
|
||||
const recipient = user ? user.get('username') : '',
|
||||
reply = post ? window.location.protocol + "//" + window.location.host + post.get("url") : null;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{{user-menu visible=userMenuVisible}}
|
||||
{{user-menu visible=userMenuVisible logoutAction="logout"}}
|
||||
{{hamburger-menu visible=hamburgerVisible showKeyboardAction="showKeyboardShortcutsHelp"}}
|
||||
{{search-menu visible=searchVisible}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue