2014-10-25 01:09:50 +04:00
|
|
|
import ajax from 'ghost/utils/ajax';
|
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
|
|
|
|
|
|
|
var ForgottenController = Ember.Controller.extend(ValidationEngine, {
|
|
|
|
email: '',
|
|
|
|
submitting: false,
|
|
|
|
|
|
|
|
// ValidationEngine settings
|
|
|
|
validationType: 'forgotten',
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
submit: function () {
|
|
|
|
var self = this,
|
|
|
|
data = self.getProperties('email');
|
|
|
|
|
|
|
|
this.toggleProperty('submitting');
|
|
|
|
this.validate({format: false}).then(function () {
|
|
|
|
ajax({
|
|
|
|
url: self.get('ghostPaths.url').api('authentication', 'passwordreset'),
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
passwordreset: [{
|
|
|
|
email: data.email
|
|
|
|
}]
|
|
|
|
}
|
2014-11-28 02:45:34 +03:00
|
|
|
}).then(function () {
|
2014-10-25 01:09:50 +04:00
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showSuccess('Please check your email for instructions.', {delayed: true});
|
|
|
|
self.set('email', '');
|
|
|
|
self.transitionToRoute('signin');
|
|
|
|
}).catch(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
2014-11-28 02:45:34 +03:00
|
|
|
self.notifications.showAPIError(resp, {defaultErrorText: 'There was a problem with the reset, please try again.'});
|
2014-10-25 01:09:50 +04:00
|
|
|
});
|
|
|
|
}).catch(function (errors) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showErrors(errors);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ForgottenController;
|