2014-06-27 23:08:16 +04:00
|
|
|
import ajax from 'ghost/utils/ajax';
|
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
|
|
|
|
|
|
|
var ResetController = Ember.Controller.extend(ValidationEngine, {
|
2014-10-02 19:12:54 +04:00
|
|
|
newPassword: '',
|
|
|
|
ne2Password: '',
|
2014-03-31 13:57:50 +04:00
|
|
|
token: '',
|
2015-02-13 02:16:18 +03:00
|
|
|
submitting: false,
|
2014-06-27 23:08:16 +04:00
|
|
|
|
|
|
|
validationType: 'reset',
|
|
|
|
|
2014-10-02 19:12:54 +04:00
|
|
|
email: Ember.computed('token', function () {
|
|
|
|
// The token base64 encodes the email (and some other stuff),
|
|
|
|
// each section is divided by a '|'. Email comes second.
|
|
|
|
return atob(this.get('token')).split('|')[1];
|
|
|
|
}),
|
|
|
|
|
|
|
|
// Used to clear sensitive information
|
|
|
|
clearData: function () {
|
|
|
|
this.setProperties({
|
|
|
|
newPassword: '',
|
|
|
|
ne2Password: '',
|
|
|
|
token: ''
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-03-31 13:57:50 +04:00
|
|
|
actions: {
|
|
|
|
submit: function () {
|
2014-10-02 19:12:54 +04:00
|
|
|
var credentials = this.getProperties('newPassword', 'ne2Password', 'token'),
|
|
|
|
self = this;
|
2014-06-27 23:08:16 +04:00
|
|
|
|
|
|
|
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: {
|
2014-10-02 19:12:54 +04:00
|
|
|
passwordreset: [credentials]
|
2014-06-27 23:08:16 +04:00
|
|
|
}
|
|
|
|
}).then(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
2014-08-01 12:56:29 +04:00
|
|
|
self.notifications.showSuccess(resp.passwordreset[0].message, true);
|
2014-10-02 19:12:54 +04:00
|
|
|
self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', {
|
|
|
|
identification: self.get('email'),
|
|
|
|
password: credentials.newPassword
|
|
|
|
});
|
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;
|