mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
cb59388c5b
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.
78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
import DS from 'ember-data';
|
|
import EmberObject from 'ember-object';
|
|
import RSVP from 'rsvp';
|
|
import Route from 'ember-route';
|
|
import UnauthenticatedRouteMixin from 'ghost-admin/mixins/unauthenticated-route-mixin';
|
|
import injectService from 'ember-service/inject';
|
|
import styleBody from 'ghost-admin/mixins/style-body';
|
|
|
|
const {Promise} = RSVP;
|
|
const {Errors} = DS;
|
|
|
|
export default Route.extend(styleBody, UnauthenticatedRouteMixin, {
|
|
classNames: ['ghost-signup'],
|
|
|
|
ghostPaths: injectService(),
|
|
notifications: injectService(),
|
|
session: injectService(),
|
|
ajax: injectService(),
|
|
|
|
beforeModel() {
|
|
if (this.get('session.isAuthenticated')) {
|
|
this.get('notifications').showAlert('You need to sign out to register as a new user.', {type: 'warn', delayed: true, key: 'signup.create.already-authenticated'});
|
|
}
|
|
|
|
this._super(...arguments);
|
|
},
|
|
|
|
model(params) {
|
|
let model = EmberObject.create();
|
|
let re = /^(?:[A-Za-z0-9_\-]{4})*(?:[A-Za-z0-9_\-]{2}|[A-Za-z0-9_\-]{3})?$/;
|
|
let email,
|
|
tokenText;
|
|
|
|
return new Promise((resolve) => {
|
|
if (!re.test(params.token)) {
|
|
this.get('notifications').showAlert('Invalid token.', {type: 'error', delayed: true, key: 'signup.create.invalid-token'});
|
|
|
|
return resolve(this.transitionTo('signin'));
|
|
}
|
|
|
|
tokenText = atob(params.token);
|
|
email = tokenText.split('|')[1];
|
|
|
|
model.set('email', email);
|
|
model.set('token', params.token);
|
|
model.set('errors', Errors.create());
|
|
|
|
let authUrl = this.get('ghostPaths.url').api('authentication', 'invitation');
|
|
|
|
return this.get('ajax').request(authUrl, {
|
|
dataType: 'json',
|
|
data: {
|
|
email
|
|
}
|
|
}).then((response) => {
|
|
if (response && response.invitation && response.invitation[0].valid === false) {
|
|
this.get('notifications').showAlert('The invitation does not exist or is no longer valid.', {type: 'warn', delayed: true, key: 'signup.create.invalid-invitation'});
|
|
|
|
return resolve(this.transitionTo('signin'));
|
|
}
|
|
|
|
model.set('invitedBy', response.invitation[0].invitedBy);
|
|
|
|
resolve(model);
|
|
}).catch(() => {
|
|
resolve(model);
|
|
});
|
|
});
|
|
},
|
|
|
|
deactivate() {
|
|
this._super(...arguments);
|
|
|
|
// clear the properties that hold the sensitive data from the controller
|
|
this.controllerFor('signup').setProperties({email: '', password: '', token: ''});
|
|
}
|
|
});
|