2014-06-27 23:08:16 +04:00
|
|
|
/*global console*/
|
|
|
|
/* jshint unused: false */
|
|
|
|
import ajax from 'ghost/utils/ajax';
|
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
|
|
|
|
|
|
|
var ResetController = Ember.Controller.extend(ValidationEngine, {
|
2014-03-31 13:57:50 +04:00
|
|
|
passwords: {
|
|
|
|
newPassword: '',
|
|
|
|
ne2Password: ''
|
|
|
|
},
|
|
|
|
token: '',
|
|
|
|
submitButtonDisabled: false,
|
2014-06-27 23:08:16 +04:00
|
|
|
|
|
|
|
validationType: 'reset',
|
|
|
|
|
2014-03-31 13:57:50 +04:00
|
|
|
actions: {
|
|
|
|
submit: function () {
|
2014-06-27 23:08:16 +04:00
|
|
|
var self = this,
|
|
|
|
data = self.getProperties('passwords', 'token');
|
|
|
|
|
|
|
|
this.toggleProperty('submitting');
|
|
|
|
this.validate({format: false}).then(function () {
|
|
|
|
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: 'PUT',
|
|
|
|
data: {
|
|
|
|
passwordreset: [{
|
|
|
|
newPassword: data.passwords.newPassword,
|
|
|
|
ne2Password: data.passwords.ne2Password,
|
|
|
|
token: data.token
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}).then(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
2014-08-01 12:56:29 +04:00
|
|
|
self.notifications.showSuccess(resp.passwordreset[0].message, true);
|
2014-03-31 13:57:50 +04:00
|
|
|
self.transitionToRoute('signin');
|
2014-08-01 12:56:29 +04:00
|
|
|
}).catch(function (response) {
|
|
|
|
self.notifications.showAPIError(response);
|
2014-06-27 23:08:16 +04:00
|
|
|
self.toggleProperty('submitting');
|
2014-03-31 13:57:50 +04:00
|
|
|
});
|
2014-06-27 23:08:16 +04:00
|
|
|
}).catch(function (error) {
|
|
|
|
self.toggleProperty('submitting');
|
2014-07-23 01:03:57 +04:00
|
|
|
self.notifications.showErrors(error);
|
2014-06-27 23:08:16 +04:00
|
|
|
});
|
2014-03-31 13:57:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ResetController;
|