mirror of
https://github.com/TryGhost/Ghost-Admin.git
synced 2023-12-14 02:33:04 +01:00
1e3e2e853a
No issue - ember-simple-auth@0.8.0-beta.2. - Switch from SimpleAuth global to ember-cli-simple-auth and ES6 imports. - Refactor controllers to handle changes in 0.8. - Introduces a new initializer to override some configuration items that are set in environment.js but need to be set with information that's only (easily) available at runtime.
67 lines
2.5 KiB
JavaScript
67 lines
2.5 KiB
JavaScript
import Ember from 'ember';
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
|
import ajax from 'ghost/utils/ajax';
|
|
|
|
var SigninController = Ember.Controller.extend(ValidationEngine, {
|
|
validationType: 'signin',
|
|
|
|
submitting: false,
|
|
|
|
actions: {
|
|
authenticate: function () {
|
|
var model = this.get('model'),
|
|
authStrategy = 'simple-auth-authenticator:oauth2-password-grant',
|
|
data = model.getProperties('identification', 'password');
|
|
|
|
this.get('session').authenticate(authStrategy, data).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.
|
|
});
|
|
},
|
|
|
|
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);
|
|
});
|
|
},
|
|
|
|
forgotten: function () {
|
|
var email = this.get('model.identification'),
|
|
self = this;
|
|
|
|
if (!email) {
|
|
return this.notifications.showError('Enter email address to reset password.');
|
|
}
|
|
|
|
self.set('submitting', true);
|
|
|
|
ajax({
|
|
url: self.get('ghostPaths.url').api('authentication', 'passwordreset'),
|
|
type: 'POST',
|
|
data: {
|
|
passwordreset: [{
|
|
email: email
|
|
}]
|
|
}
|
|
}).then(function () {
|
|
self.set('submitting', false);
|
|
self.notifications.showSuccess('Please check your email for instructions.');
|
|
}).catch(function (resp) {
|
|
self.set('submitting', false);
|
|
self.notifications.showAPIError(resp, {defaultErrorText: 'There was a problem with the reset, please try again.'});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
export default SigninController;
|