Ghost/ghost/admin/routes/signup.js
shindakun 5d7630607b Transition to signin with error message on invalid token not 500 error screen
closes #3548
- Add error to hidenav, removes menubar from error screen.
- Wrap atob() in a try/catch
- Added regex to try and validate if params.token at least looks like base64
2014-08-06 08:08:02 -07:00

34 lines
1.3 KiB
JavaScript

import styleBody from 'ghost/mixins/style-body';
import loadingIndicator from 'ghost/mixins/loading-indicator';
var SignupRoute = Ember.Route.extend(styleBody, loadingIndicator, {
classNames: ['ghost-signup'],
beforeModel: function () {
if (this.get('session').isAuthenticated) {
this.notifications.showWarn('You need to sign out to register as a new user.', { delayed: true });
this.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication);
}
},
setupController: function (controller, params) {
var tokenText,
email,
re = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/;
if (re.test(params.token)) {
try {
tokenText = atob(params.token);
email = tokenText.split('|')[1];
controller.token = params.token;
controller.email = email;
} catch (e) {
this.transitionTo('signin');
this.notifications.showError('Invalid token.', {delayed: true});
}
} else {
this.transitionTo('signin');
this.notifications.showError('Invalid token.', {delayed: true});
}
}
});
export default SignupRoute;