Skip to content

Commit

Permalink
Merge pull request TryGhost#4602 from jaswilli/better-auth-retry
Browse files Browse the repository at this point in the history
Allow re-authentication in editor after 401 response
  • Loading branch information
sebgie committed Dec 15, 2014
2 parents a0db21d + 1541b92 commit 7a0fe7c
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 21 deletions.
37 changes: 36 additions & 1 deletion core/client/assets/sass/components/modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,39 @@

.modal-style-centered {
text-align: center;
}
}

// 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;
}
}
}
30 changes: 30 additions & 0 deletions core/client/controllers/modals/signin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 () {
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');
}
}
});
2 changes: 1 addition & 1 deletion core/client/initializers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
Expand Down
26 changes: 9 additions & 17 deletions core/client/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,18 @@ 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');
},

openSettingsMenu: function () {
this.set('controller.showSettingsMenu', true);
},

closeSettingsMenu: function () {
this.set('controller.showSettingsMenu', false);
},

toggleSettingsMenu: function () {
this.toggleProperty('controller.showSettingsMenu');
},
Expand Down Expand Up @@ -77,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');
Expand Down
6 changes: 6 additions & 0 deletions core/client/routes/editor/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ var EditorEditRoute = AuthenticatedRoute.extend(base, {
return self.replaceWith('posts.index');
}
});
},

actions: {
authorizationFailed: function () {
this.send('openModal', 'signin');
}
}
});

Expand Down
11 changes: 11 additions & 0 deletions core/client/templates/modals/signin.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide" animation="fade"
title="Please re-authenticate" confirm=confirm}}

<form id="login" class="login-form" method="post" novalidate="novalidate" {{action "validateAndAuthenticate" on="submit"}}>
<div class="password-wrap">
{{input class="password" type="password" placeholder="Password" name="password" value=password}}
</div>
<button class="btn btn-blue" type="submit" {{action "validateAndAuthenticate"}} {{bind-attr disabled=submitting}}>Log in</button>
</form>

{{/gh-modal-dialog}}
3 changes: 1 addition & 2 deletions core/client/templates/signin.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<form id="login" class="login-form" method="post" novalidate="novalidate" {{action 'validateAndAuthenticate' on='submit'}}>
<div class="email-wrap">
<span class="input-icon icon-mail">
{{gh-trim-focus-input class="email" type="email" placeholder="Email Address" name="identification"
autocapitalize="off" autocorrect="off" value=identification}}
{{gh-trim-focus-input class="email" type="email" placeholder="Email Address" name="identification" autocapitalize="off" autocorrect="off" value=identification}}
</span>
</div>
<div class="password-wrap">
Expand Down

0 comments on commit 7a0fe7c

Please sign in to comment.