Ghost/ghost/admin/app/controllers/reset.js
Kevin Ansfield cb59388c5b 💄🐷 sort-imports eslint rule (#712)
no issue

- adds `eslint-plugin-sort-imports-es6-autofix` dependency
  - implements ESLint's base `sort-imports` rule but has a distinction in that `import {foo} from 'bar';` is considered `multiple` rather than `single`
  - fixes ESLint's autofix behaviour so `eslint --fix` will actually fix the sort order
- updates all unordered import rules by using `eslint --fix`

With the increased number of `import` statements since Ember+ecosystem started moving towards es6 modules I've found it frustrating at times trying to search through randomly ordered import statements. Recently I've been sorting imports manually when I've added new code or touched old code so I thought I'd add an ESLint rule to codify it.
2017-05-29 20:50:03 +02:00

76 lines
2.4 KiB
JavaScript

import Controller from 'ember-controller';
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
import computed from 'ember-computed';
import injectService from 'ember-service/inject';
import {task} from 'ember-concurrency';
export default Controller.extend(ValidationEngine, {
newPassword: '',
ne2Password: '',
token: '',
flowErrors: '',
validationType: 'reset',
ghostPaths: injectService(),
notifications: injectService(),
session: injectService(),
ajax: injectService(),
email: 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() {
this.setProperties({
newPassword: '',
ne2Password: '',
token: ''
});
},
resetPassword: task(function* () {
let credentials = this.getProperties('newPassword', 'ne2Password', 'token');
let authUrl = this.get('ghostPaths.url').api('authentication', 'passwordreset');
this.set('flowErrors', '');
this.get('hasValidated').addObjects(['newPassword', 'ne2Password']);
try {
yield this.validate();
try {
let resp = yield this.get('ajax').put(authUrl, {
data: {
passwordreset: [credentials]
}
});
this.get('notifications').showAlert(resp.passwordreset[0].message, {type: 'warn', delayed: true, key: 'password.reset'});
this.get('session').authenticate('authenticator:oauth2', this.get('email'), credentials.newPassword);
} catch (error) {
this.get('notifications').showAPIError(error, {key: 'password.reset'});
}
} catch (error) {
if (this.get('errors.newPassword')) {
this.set('flowErrors', this.get('errors.newPassword')[0].message);
}
if (this.get('errors.ne2Password')) {
this.set('flowErrors', this.get('errors.ne2Password')[0].message);
}
if (error && this.get('errors.length') === 0) {
throw error;
}
}
}).drop(),
actions: {
submit() {
this.get('resetPassword').perform();
}
}
});