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({
|
|
|
|
url: self.get('ghostPaths').apiUrl('authentication', 'passwordreset'),
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
passwordreset: [{
|
|
|
|
email: data.email
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}).then(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showSuccess('Please check your email for instructions.');
|
|
|
|
self.transitionToRoute('signin');
|
|
|
|
}).catch(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showAPIError(resp, 'There was a problem logging in, please try again.');
|
|
|
|
});
|
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;
|