From 32648147e28c8c76c2d1e7680ff6348dfde8d2ae Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 6 Aug 2015 15:04:20 +0930 Subject: [PATCH] Reload page on login closes flarum/core#145 --- js/forum/src/components/DiscussionPage.js | 3 --- js/lib/Session.js | 32 +++-------------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/js/forum/src/components/DiscussionPage.js b/js/forum/src/components/DiscussionPage.js index ac2294eeb..bcfb15c47 100644 --- a/js/forum/src/components/DiscussionPage.js +++ b/js/forum/src/components/DiscussionPage.js @@ -55,8 +55,6 @@ export default class DiscussionPage extends mixin(Component, evented) { app.current = this; app.drawer.hide(); app.modal.close(); - - app.session.on('loggedIn', this.loggedInHandler = this.refresh.bind(this)); } onunload(e) { @@ -81,7 +79,6 @@ export default class DiscussionPage extends mixin(Component, evented) { // discussion, minimize the composer – unless it's empty, in which case // we'll just close it. app.pane.disable(); - app.session.off('loggedIn', this.loggedInHandler); if (app.composingReplyTo(this.discussion) && !app.composer.component.content()) { app.composer.hide(); diff --git a/js/lib/Session.js b/js/lib/Session.js index 3d67b1a91..3feaf21f4 100644 --- a/js/lib/Session.js +++ b/js/lib/Session.js @@ -1,13 +1,8 @@ -import mixin from 'flarum/utils/mixin'; -import evented from 'flarum/utils/evented'; - /** * The `Session` class defines the current user session. It stores a reference * to the current authenticated user, and provides methods to log in/out. - * - * @extends evented */ -export default class Session extends mixin(class {}, evented) { +export default class Session { constructor(token, user) { super(); @@ -35,31 +30,12 @@ export default class Session extends mixin(class {}, evented) { * @return {Promise} */ login(identification, password) { - const deferred = m.deferred(); - - app.request({ + return app.request({ method: 'POST', url: app.forum.attribute('baseUrl') + '/login', data: {identification, password} - }).then( - // FIXME: reload the page on success. Somehow serialize what the user's - // intention was, and then perform that intention after the page reloads. - response => { - this.token = response.token; - - app.store.find('users', response.userId).then(user => { - this.user = user; - this.trigger('loggedIn', user); - deferred.resolve(user); - }); - }, - - response => { - deferred.reject(response); - } - ); - - return deferred.promise; + }) + .then(() => window.location.reload()); } /**