2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
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 () {
|
2015-03-30 20:52:48 +03:00
|
|
|
var data = this.getProperties('email');
|
|
|
|
this.send('doForgotten', data, true);
|
|
|
|
},
|
|
|
|
doForgotten: function (data, delay) {
|
|
|
|
var self = this;
|
|
|
|
this.set('email', data.email);
|
2014-10-25 01:09:50 +04:00
|
|
|
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');
|
2015-03-30 20:52:48 +03:00
|
|
|
self.notifications.showSuccess('Please check your email for instructions.', {delayed: delay});
|
2014-10-25 01:09:50 +04:00
|
|
|
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;
|