0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-18 02:21:47 -05:00

Merge pull request #4602 from jaswilli/better-auth-retry

Allow re-authentication in editor after 401 response
This commit is contained in:
Sebastian Gierlinger 2014-12-15 16:57:11 +02:00
commit 7a0fe7c431
7 changed files with 94 additions and 21 deletions

View file

@ -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;
}
}
}

View file

@ -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');
}
}
});

View file

@ -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'
};

View file

@ -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');
},
@ -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');

View file

@ -48,6 +48,12 @@ var EditorEditRoute = AuthenticatedRoute.extend(base, {
return self.replaceWith('posts.index');
}
});
},
actions: {
authorizationFailed: function () {
this.send('openModal', 'signin');
}
}
});

View file

@ -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}}

View file

@ -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">