mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
352c4af1d7
no issue - ran [es5-getter-ember-codemod](https://github.com/rondale-sc/es5-getter-ember-codemod) - [es5 getters RFC](https://github.com/emberjs/rfcs/blob/master/text/0281-es5-getters.md) - updates the majority of `object.get('property')` with `object.property` with exceptions: - `.get('nested.property')` - it's not possible to determine if this is relying on "safe" path chaining for when `nested` doesn't exist - `.get('config.x')` and `.get('settings.x')` - both our `config` and `settings` services are proxy objects which do not support es5 getters - this PR is not exhaustive, there are still a number of places where `.get('service.foo')` and similar could be replaced but it gets us a long way there in a quick and automated fashion
87 lines
3.1 KiB
JavaScript
87 lines
3.1 KiB
JavaScript
import DS from 'ember-data';
|
|
import EmberObject from '@ember/object';
|
|
import RSVP from 'rsvp';
|
|
import Route from '@ember/routing/route';
|
|
import UnauthenticatedRouteMixin from 'ghost-admin/mixins/unauthenticated-route-mixin';
|
|
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
|
import styleBody from 'ghost-admin/mixins/style-body';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
const {Promise} = RSVP;
|
|
const {Errors} = DS;
|
|
|
|
export default Route.extend(styleBody, UnauthenticatedRouteMixin, {
|
|
ghostPaths: service(),
|
|
notifications: service(),
|
|
session: service(),
|
|
ajax: service(),
|
|
config: service(),
|
|
|
|
classNames: ['ghost-signup'],
|
|
|
|
beforeModel() {
|
|
if (this.get('session.isAuthenticated')) {
|
|
this.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 SignupDetails = EmberObject.extend(ValidationEngine, {
|
|
validationType: 'signup'
|
|
});
|
|
let signupDetails = SignupDetails.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.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];
|
|
|
|
// leave e-mail blank even though we get it from the token because
|
|
// we need the user to type it in for Chrome to remember the
|
|
// email/password combo properly
|
|
signupDetails.set('email', '');
|
|
signupDetails.set('token', params.token);
|
|
signupDetails.set('errors', Errors.create());
|
|
|
|
let authUrl = this.get('ghostPaths.url').api('authentication', 'invitation');
|
|
|
|
return this.ajax.request(authUrl, {
|
|
dataType: 'json',
|
|
data: {
|
|
email
|
|
}
|
|
}).then((response) => {
|
|
if (response && response.invitation && response.invitation[0].valid === false) {
|
|
this.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'));
|
|
}
|
|
|
|
// set blogTitle, so password validation has access to it
|
|
signupDetails.set('blogTitle', this.get('config.blogTitle'));
|
|
|
|
resolve(signupDetails);
|
|
}).catch(() => {
|
|
resolve(signupDetails);
|
|
});
|
|
});
|
|
},
|
|
|
|
deactivate() {
|
|
this._super(...arguments);
|
|
|
|
// clear the properties that hold the sensitive data from the controller
|
|
this.controllerFor('signup').get('signupDetails').setProperties({email: '', password: '', token: ''});
|
|
}
|
|
});
|