2015-11-18 13:50:48 +03:00
|
|
|
import Ember from 'ember';
|
2016-05-24 15:06:59 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modals/base';
|
|
|
|
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
2015-11-18 13:50:48 +03:00
|
|
|
|
2016-01-19 16:03:27 +03:00
|
|
|
const {
|
|
|
|
$,
|
|
|
|
computed,
|
2016-06-11 19:52:36 +03:00
|
|
|
inject: {service},
|
|
|
|
String: {htmlSafe}
|
2016-01-19 16:03:27 +03:00
|
|
|
} = Ember;
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
export default ModalComponent.extend(ValidationEngine, {
|
|
|
|
validationType: 'signin',
|
|
|
|
|
|
|
|
submitting: false,
|
|
|
|
authenticationError: null,
|
|
|
|
|
2016-01-19 16:03:27 +03:00
|
|
|
notifications: service(),
|
|
|
|
session: service(),
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
identification: computed('session.user.email', function () {
|
|
|
|
return this.get('session.user.email');
|
|
|
|
}),
|
|
|
|
|
|
|
|
_authenticate() {
|
|
|
|
let session = this.get('session');
|
|
|
|
let authStrategy = 'authenticator:oauth2';
|
|
|
|
let identification = this.get('identification');
|
|
|
|
let password = this.get('password');
|
|
|
|
|
|
|
|
session.set('skipAuthSuccessHandler', true);
|
|
|
|
|
|
|
|
this.toggleProperty('submitting');
|
|
|
|
|
|
|
|
return session.authenticate(authStrategy, identification, password).finally(() => {
|
|
|
|
this.toggleProperty('submitting');
|
|
|
|
session.set('skipAuthSuccessHandler', undefined);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
confirm() {
|
|
|
|
// 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.set('authenticationError', null);
|
|
|
|
|
|
|
|
this.validate({property: 'signin'}).then(() => {
|
|
|
|
this._authenticate().then(() => {
|
|
|
|
this.get('notifications').closeAlerts('post.save');
|
|
|
|
this.send('closeModal');
|
|
|
|
}).catch((error) => {
|
|
|
|
if (error && error.errors) {
|
|
|
|
error.errors.forEach((err) => {
|
2016-06-11 19:52:36 +03:00
|
|
|
err.message = htmlSafe(err.message);
|
2015-11-18 13:50:48 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
this.get('errors').add('password', 'Incorrect password');
|
|
|
|
this.get('hasValidated').pushObject('password');
|
|
|
|
this.set('authenticationError', error.errors[0].message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, () => {
|
|
|
|
this.get('hasValidated').pushObject('password');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|