From 1961b075bbde16074d6102cd8074f6cea33a5602 Mon Sep 17 00:00:00 2001 From: Marco Otte-Witte Date: Thu, 31 Jul 2014 21:15:55 +0200 Subject: [PATCH 1/2] allow re-login when authorization fails on editor.edit route --- core/client/controllers/modals/signin.js | 12 ++++++++++++ core/client/initializers/authentication.js | 4 ++-- core/client/routes/application.js | 18 ++---------------- core/client/routes/editor/edit.js | 6 ++++++ core/client/templates/modals/signin.hbs | 14 ++++++++++++++ core/client/templates/signin.hbs | 3 +-- 6 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 core/client/controllers/modals/signin.js create mode 100644 core/client/templates/modals/signin.hbs diff --git a/core/client/controllers/modals/signin.js b/core/client/controllers/modals/signin.js new file mode 100644 index 00000000000..bcbb24579f5 --- /dev/null +++ b/core/client/controllers/modals/signin.js @@ -0,0 +1,12 @@ +import SigninController from '../signin'; + +export default SigninController.extend({ + actions: { + authenticate: function (data) { + var self = this; + this._super(data).then(function () { + self.send('closeModal'); + }); + } + } +}); diff --git a/core/client/initializers/authentication.js b/core/client/initializers/authentication.js index 9861cb4e5cf..7bb49c26988 100644 --- a/core/client/initializers/authentication.js +++ b/core/client/initializers/authentication.js @@ -27,9 +27,9 @@ AuthenticationInitializer = { }; SimpleAuth.Session.reopen({ - user: Ember.computed(function () { + user: function () { return container.lookup('store:main').find('user', 'me'); - }) + }).property() }); SimpleAuth.Authenticators.OAuth2.reopen({ diff --git a/core/client/routes/application.js b/core/client/routes/application.js index efae553d1be..c6aadc7182b 100644 --- a/core/client/routes/application.js +++ b/core/client/routes/application.js @@ -23,22 +23,6 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut }, actions: { - authorizationFailed: function () { - var currentRoute = this.get('controller').get('currentRouteName'), - editorController; - - if (currentRoute.split('.')[0] === 'editor') { - editorController = this.controllerFor(currentRoute); - - if (editorController.get('isDirty')) { - this.send('openModal', 'auth-failed-unsaved', editorController); - return; - } - } - - this._super(); - }, - toggleGlobalMobileNav: function () { this.toggleProperty('controller.showGlobalMobileNav'); }, @@ -46,9 +30,11 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut openSettingsMenu: function () { this.set('controller.showSettingsMenu', true); }, + closeSettingsMenu: function () { this.set('controller.showSettingsMenu', false); }, + toggleSettingsMenu: function () { this.toggleProperty('controller.showSettingsMenu'); }, diff --git a/core/client/routes/editor/edit.js b/core/client/routes/editor/edit.js index 094040a7f06..d067bd37e2f 100644 --- a/core/client/routes/editor/edit.js +++ b/core/client/routes/editor/edit.js @@ -48,6 +48,12 @@ var EditorEditRoute = AuthenticatedRoute.extend(base, { return self.replaceWith('posts.index'); } }); + }, + + actions: { + authorizationFailed: function () { + this.send('openModal', 'signin'); + } } }); diff --git a/core/client/templates/modals/signin.hbs b/core/client/templates/modals/signin.hbs new file mode 100644 index 00000000000..2006f8d40bf --- /dev/null +++ b/core/client/templates/modals/signin.hbs @@ -0,0 +1,14 @@ +{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide,centered" animation="fade" + title="Please login again" confirm=confirm}} + +
+ +
+ {{input class="password" type="password" placeholder="Password" name="password" value=password}} +
+ +
+ +{{/gh-modal-dialog}} diff --git a/core/client/templates/signin.hbs b/core/client/templates/signin.hbs index f2257747593..27e2d54e1f8 100644 --- a/core/client/templates/signin.hbs +++ b/core/client/templates/signin.hbs @@ -2,8 +2,7 @@
From 1541b92ccf379fedb60098564f90954884f7f202 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Mon, 8 Dec 2014 00:31:24 +0000 Subject: [PATCH 2/2] Fixup behavior and styling of editor re-auth. Closes #2092 - Adds styling for re-auth modal. - Prevent transition to posts route on success. - Clear credentials from controller. - Handle confirmAccept action if form is submitted via 'enter'. - Only allow re-auth as the user that was previously logged in. --- .../client/assets/sass/components/modals.scss | 37 ++++++++++++++++++- core/client/controllers/modals/signin.js | 26 +++++++++++-- core/client/initializers/authentication.js | 6 +-- core/client/routes/application.js | 8 +++- core/client/templates/modals/signin.hbs | 11 ++---- 5 files changed, 72 insertions(+), 16 deletions(-) diff --git a/core/client/assets/sass/components/modals.scss b/core/client/assets/sass/components/modals.scss index c856adb5e1a..c661498dadf 100644 --- a/core/client/assets/sass/components/modals.scss +++ b/core/client/assets/sass/components/modals.scss @@ -165,4 +165,39 @@ .modal-style-centered { text-align: center; -} \ No newline at end of file +} + +// Modal login styles +.modal-body .login-form { + display: block; // Override inherited `display: table-cell;` + + .password-wrap { + input { + width: 100%; + } + } + + @media (max-width: 900px) { + margin: 0 auto; + max-width: 264px; + + .password-wrap { + width: 100%; + margin: 0 auto 1em; + } + + .btn { + margin: 0; + width: 100%; + margin-bottom: 1em; + } + } + + @media (min-width: 901px) { + display: flex; + + .password-wrap { + flex: 1; + } + } +} diff --git a/core/client/controllers/modals/signin.js b/core/client/controllers/modals/signin.js index bcbb24579f5..2d3d82b28cd 100644 --- a/core/client/controllers/modals/signin.js +++ b/core/client/controllers/modals/signin.js @@ -1,12 +1,30 @@ -import SigninController from '../signin'; +import SigninController from 'ghost/controllers/signin'; export default SigninController.extend({ + needs: 'application', + + identification: Ember.computed('session.user.email', function () { + return this.get('session.user.email'); + }), + actions: { - authenticate: function (data) { - var self = this; - this._super(data).then(function () { + authenticate: function () { + var appController = this.get('controllers.application'), + self = this; + + appController.set('skipAuthSuccessHandler', true); + + this._super().then(function () { self.send('closeModal'); + self.notifications.showSuccess('Login successful.'); + self.set('password', ''); + }).finally(function () { + appController.set('skipAuthSuccessHandler', undefined); }); + }, + + confirmAccept: function () { + this.send('validateAndAuthenticate'); } } }); diff --git a/core/client/initializers/authentication.js b/core/client/initializers/authentication.js index 7bb49c26988..2846d9d0a55 100644 --- a/core/client/initializers/authentication.js +++ b/core/client/initializers/authentication.js @@ -15,7 +15,7 @@ AuthenticationInitializer = { window.ENV['simple-auth'] = { authenticationRoute: 'signin', - routeAfterAuthentication: 'content', + routeAfterAuthentication: 'posts', authorizer: 'simple-auth-authorizer:oauth2-bearer', localStorageKey: 'ghost' + (Ghost.subdir.indexOf('/') === 0 ? '-' + Ghost.subdir.substr(1) : '') + ':session' }; @@ -27,9 +27,9 @@ AuthenticationInitializer = { }; SimpleAuth.Session.reopen({ - user: function () { + user: Ember.computed(function () { return container.lookup('store:main').find('user', 'me'); - }).property() + }) }); SimpleAuth.Authenticators.OAuth2.reopen({ diff --git a/core/client/routes/application.js b/core/client/routes/application.js index c6aadc7182b..986d87ccc44 100644 --- a/core/client/routes/application.js +++ b/core/client/routes/application.js @@ -63,7 +63,13 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut }, sessionAuthenticationSucceeded: function () { - var self = this; + var appController = this.controllerFor('application'), + self = this; + + if (appController && appController.get('skipAuthSuccessHandler')) { + return; + } + this.store.find('user', 'me').then(function (user) { self.send('signedIn', user); var attemptedTransition = self.get('session').get('attemptedTransition'); diff --git a/core/client/templates/modals/signin.hbs b/core/client/templates/modals/signin.hbs index 2006f8d40bf..e77058ba73c 100644 --- a/core/client/templates/modals/signin.hbs +++ b/core/client/templates/modals/signin.hbs @@ -1,14 +1,11 @@ -{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide,centered" animation="fade" - title="Please login again" confirm=confirm}} +{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide" animation="fade" + title="Please re-authenticate" confirm=confirm}} - - +
{{input class="password" type="password" placeholder="Password" name="password" value=password}}
- + {{/gh-modal-dialog}}