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