Skip to content

Commit

Permalink
Adjust reauth modal to handle removal of proxying
Browse files Browse the repository at this point in the history
Closes TryGhost#4907.
- The modal signin no longer inherits from the signin page
  controller to simplify the interaction with simple-auth.
  • Loading branch information
jaswilli committed Feb 13, 2015
1 parent f073e10 commit 6cc715d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
29 changes: 26 additions & 3 deletions core/client/controllers/modals/signin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import SigninController from 'ghost/controllers/signin';
import ValidationEngine from 'ghost/mixins/validation-engine';

export default SigninController.extend({
export default Ember.Controller.extend(SimpleAuth.AuthenticationControllerMixin, ValidationEngine, {
needs: 'application',

authenticator: 'simple-auth-authenticator:oauth2-password-grant',

validationType: 'signin',

identification: Ember.computed('session.user.email', function () {
return this.get('session.user.email');
}),
Expand All @@ -14,15 +18,34 @@ export default SigninController.extend({

appController.set('skipAuthSuccessHandler', true);

this._super().then(function () {
this._super(this.getProperties('identification', 'password')).then(function () {
self.send('closeModal');
self.notifications.showSuccess('Login successful.');
self.set('password', '');
}).catch(function () {
// if authentication fails a rejected promise will be returned.
// it needs to be caught so it doesn't generate an exception in the console,
// but it's actually "handled" by the sessionAuthenticationFailed action handler.
}).finally(function () {
appController.set('skipAuthSuccessHandler', undefined);
});
},

validateAndAuthenticate: function () {
var self = this;

// Manually trigger events for input fields, ensuring legacy compatibility with
// browsers and password managers that don't send proper events on autofill
$('#login').find('input').trigger('change');

this.validate({format: false}).then(function () {
self.notifications.closePassive();
self.send('authenticate');
}).catch(function (errors) {
self.notifications.showErrors(errors);
});
},

confirmAccept: function () {
this.send('validateAndAuthenticate');
}
Expand Down
5 changes: 3 additions & 2 deletions core/client/controllers/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControll
data = model.getProperties('identification', 'password');

this._super(data).catch(function () {
// If simple-auth's authenticate rejects we need to catch it
// to avoid an unhandled rejection exception.
// if authentication fails a rejected promise will be returned.
// it needs to be caught so it doesn't generate an exception in the console,
// but it's actually "handled" by the sessionAuthenticationFailed action handler.
});
},

Expand Down

0 comments on commit 6cc715d

Please sign in to comment.