mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 18:52:05 +03:00
c3ad1ae9e2
No Issue - Switches to the newer style of dependency injection. - Instead of injection Controllers via "needs," use Ember.inject.controller(). - Get rid of initializers that were only injecting objects into various factories. Converts these objects into Ember.Service objects and declaratively inject them where needed via Ember.inject.service(). The added benefit to this is that it's no longer a mystery where these properties/methods come from and it's straightforward to inject them where needed.
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
import Ember from 'ember';
|
|
import {request as ajax} from 'ic-ajax';
|
|
import Configuration from 'simple-auth/configuration';
|
|
import styleBody from 'ghost/mixins/style-body';
|
|
|
|
export default Ember.Route.extend(styleBody, {
|
|
classNames: ['ghost-signup'],
|
|
|
|
ghostPaths: Ember.inject.service('ghost-paths'),
|
|
notifications: Ember.inject.service(),
|
|
|
|
beforeModel: function () {
|
|
if (this.get('session').isAuthenticated) {
|
|
this.get('notifications').showWarn('You need to sign out to register as a new user.', {delayed: true});
|
|
this.transitionTo(Configuration.routeAfterAuthentication);
|
|
}
|
|
},
|
|
|
|
model: function (params) {
|
|
var self = this,
|
|
tokenText,
|
|
email,
|
|
model = Ember.Object.create(),
|
|
re = /^(?:[A-Za-z0-9_\-]{4})*(?:[A-Za-z0-9_\-]{2}|[A-Za-z0-9_\-]{3})?$/;
|
|
|
|
return new Ember.RSVP.Promise(function (resolve) {
|
|
if (!re.test(params.token)) {
|
|
self.get('notifications').showError('Invalid token.', {delayed: true});
|
|
|
|
return resolve(self.transitionTo('signin'));
|
|
}
|
|
|
|
tokenText = atob(params.token);
|
|
email = tokenText.split('|')[1];
|
|
|
|
model.set('email', email);
|
|
model.set('token', params.token);
|
|
|
|
return ajax({
|
|
url: self.get('ghostPaths.url').api('authentication', 'invitation'),
|
|
type: 'GET',
|
|
dataType: 'json',
|
|
data: {
|
|
email: email
|
|
}
|
|
}).then(function (response) {
|
|
if (response && response.invitation && response.invitation[0].valid === false) {
|
|
self.get('notifications').showError('The invitation does not exist or is no longer valid.', {delayed: true});
|
|
|
|
return resolve(self.transitionTo('signin'));
|
|
}
|
|
|
|
resolve(model);
|
|
}).catch(function () {
|
|
resolve(model);
|
|
});
|
|
});
|
|
},
|
|
|
|
deactivate: function () {
|
|
this._super();
|
|
|
|
// clear the properties that hold the sensitive data from the controller
|
|
this.controllerFor('signup').setProperties({email: '', password: '', token: ''});
|
|
}
|
|
});
|