mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 15:14:16 +08:00
Avoid calling Discourse.logout
and use an action instead
This commit is contained in:
@ -78,26 +78,6 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
|||||||
this.set('notifyCount', count);
|
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) {
|
authenticationComplete: function(options) {
|
||||||
// TODO, how to dispatch this to the controller without the container?
|
// TODO, how to dispatch this to the controller without the container?
|
||||||
var loginController = Discourse.__container__.lookup('controller:login');
|
var loginController = Discourse.__container__.lookup('controller:login');
|
||||||
|
@ -71,7 +71,7 @@ export default Ember.Component.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
logout() {
|
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
|
// Subscribe to "logout" change events via the Message Bus
|
||||||
export default {
|
export default {
|
||||||
name: "logout",
|
name: "logout",
|
||||||
@ -8,17 +10,10 @@ export default {
|
|||||||
siteSettings = container.lookup('site-settings:main');
|
siteSettings = container.lookup('site-settings:main');
|
||||||
|
|
||||||
if (!messageBus) { return; }
|
if (!messageBus) { return; }
|
||||||
|
const callback = () => logout(siteSettings);
|
||||||
|
|
||||||
messageBus.subscribe("/logout", function () {
|
messageBus.subscribe("/logout", function () {
|
||||||
var refresher = function() {
|
bootbox.dialog(I18n.t("logout"), {label: I18n.t("refresh"), callback}, {onEscape: callback, backdrop: 'static'});
|
||||||
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'});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
|
||||||
var safeLocalStorage;
|
var safeLocalStorage;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
10
app/assets/javascripts/discourse/lib/logout.js.es6
Normal file
10
app/assets/javascripts/discourse/lib/logout.js.es6
Normal file
@ -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 });
|
return UserPostsStream.create({ user: this });
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
/**
|
|
||||||
Is this user a member of staff?
|
|
||||||
|
|
||||||
@property staff
|
|
||||||
@type {Boolean}
|
|
||||||
**/
|
|
||||||
staff: Em.computed.or('admin', 'moderator'),
|
staff: Em.computed.or('admin', 'moderator'),
|
||||||
|
|
||||||
|
destroySession() {
|
||||||
|
return Discourse.ajax(`/session/${this.get('username')}`, { type: 'DELETE'});
|
||||||
|
},
|
||||||
|
|
||||||
searchContext: function() {
|
searchContext: function() {
|
||||||
return {
|
return {
|
||||||
type: 'user',
|
type: 'user',
|
||||||
@ -449,21 +447,6 @@ User.reopenClass(Singleton, {
|
|||||||
return null;
|
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
|
Checks if given username is valid for this email address
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { setting } from 'discourse/lib/computed';
|
import { setting } from 'discourse/lib/computed';
|
||||||
|
import logout from 'discourse/lib/logout';
|
||||||
import showModal from 'discourse/lib/show-modal';
|
import showModal from 'discourse/lib/show-modal';
|
||||||
import OpenComposer from "discourse/mixins/open-composer";
|
import OpenComposer from "discourse/mixins/open-composer";
|
||||||
|
|
||||||
@ -16,6 +17,11 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
|||||||
siteTitle: setting('title'),
|
siteTitle: setting('title'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
||||||
|
logout() {
|
||||||
|
this.currentUser.destroySession().then(() => logout(this.siteSettings));
|
||||||
|
},
|
||||||
|
|
||||||
_collectTitleTokens(tokens) {
|
_collectTitleTokens(tokens) {
|
||||||
tokens.push(this.get('siteTitle'));
|
tokens.push(this.get('siteTitle'));
|
||||||
Discourse.set('_docTitle', tokens.join(' - '));
|
Discourse.set('_docTitle', tokens.join(' - '));
|
||||||
|
@ -11,10 +11,6 @@ export default Discourse.Route.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
logout() {
|
|
||||||
Discourse.logout();
|
|
||||||
},
|
|
||||||
|
|
||||||
composePrivateMessage(user, post) {
|
composePrivateMessage(user, post) {
|
||||||
const recipient = user ? user.get('username') : '',
|
const recipient = user ? user.get('username') : '',
|
||||||
reply = post ? window.location.protocol + "//" + window.location.host + post.get("url") : null;
|
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"}}
|
{{hamburger-menu visible=hamburgerVisible showKeyboardAction="showKeyboardShortcutsHelp"}}
|
||||||
{{search-menu visible=searchVisible}}
|
{{search-menu visible=searchVisible}}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user