2014-06-27 14:08:16 -05:00
|
|
|
/* jshint unused: false */
|
|
|
|
import ajax from 'ghost/utils/ajax';
|
2014-06-23 19:47:51 -05:00
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
2014-03-25 18:34:30 -05:00
|
|
|
|
2014-06-23 19:47:51 -05:00
|
|
|
var ForgottenController = Ember.Controller.extend(ValidationEngine, {
|
2014-03-25 18:34:30 -05:00
|
|
|
email: '',
|
2014-06-23 19:47:51 -05:00
|
|
|
submitting: false,
|
|
|
|
|
|
|
|
// ValidationEngine settings
|
|
|
|
validationType: 'forgotten',
|
|
|
|
|
2014-03-25 18:34:30 -05:00
|
|
|
actions: {
|
|
|
|
submit: function () {
|
2014-06-27 14:08:16 -05:00
|
|
|
var self = this,
|
|
|
|
data = self.getProperties('email');
|
2014-06-23 19:47:51 -05:00
|
|
|
|
|
|
|
this.toggleProperty('submitting');
|
|
|
|
this.validate({ format: false }).then(function () {
|
2014-06-27 14:08:16 -05:00
|
|
|
ajax({
|
2014-07-12 23:01:26 -05:00
|
|
|
url: self.get('ghostPaths.url').api('authentication', 'passwordreset'),
|
2014-06-27 14:08:16 -05:00
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
passwordreset: [{
|
|
|
|
email: data.email
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}).then(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
2014-08-05 13:11:17 -05:00
|
|
|
self.notifications.showSuccess('Please check your email for instructions.', {delayed: true});
|
2014-08-07 20:28:33 -05:00
|
|
|
self.set('email', '');
|
2014-06-27 14:08:16 -05:00
|
|
|
self.transitionToRoute('signin');
|
|
|
|
}).catch(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
2014-08-01 00:40:49 -05:00
|
|
|
self.notifications.showAPIError(resp, { defaultErrorText: 'There was a problem logging in, please try again.' });
|
2014-06-27 14:08:16 -05:00
|
|
|
});
|
2014-06-23 19:47:51 -05:00
|
|
|
}).catch(function (errors) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showErrors(errors);
|
|
|
|
});
|
2014-03-25 18:34:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ForgottenController;
|