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({
|
|
|
|
url: self.get('ghostPaths').apiUrl('authentication', 'passwordreset'),
|
|
|
|
type: 'PUT',
|
|
|
|
data: {
|
|
|
|
passwordreset: [{
|
|
|
|
newPassword: data.passwords.newPassword,
|
|
|
|
ne2Password: data.passwords.ne2Password,
|
|
|
|
token: data.token
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}).then(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
console.log('success');
|
2014-03-31 13:57:50 +04:00
|
|
|
self.transitionToRoute('signin');
|
2014-06-27 23:08:16 +04:00
|
|
|
}).catch(function (errors) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
console.log('error');
|
2014-03-31 13:57:50 +04:00
|
|
|
});
|
2014-06-27 23:08:16 +04:00
|
|
|
}).catch(function (error) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
// @TODO: notifications here for validation errors
|
|
|
|
console.log('validation error', error);
|
|
|
|
});
|
2014-03-31 13:57:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ResetController;
|