Ghost/ghost/admin/app/routes/setup.js
Kevin Ansfield e01ffa3620 Always call _super when using Ember hooks
no issue
- review use of Ember core hooks and add a call to `this._super` if missing
- fix a few occurrences of using the wrong component lifecycle hooks that could result in multiple/duplicate event handlers being attached

`_super` should always be called when overriding Ember's base hooks so that core functionality or app functionality added through extensions, mixins or addons is not lost. This is important as it guards against issues arising from later refactorings or core changes.

As example of lost functionality, there were a number of routes that extended from `AuthenticatedRoute` but then overrode the `beforeModel` hook without calling `_super` which meant that the route was no longer treated as authenticated.
2015-11-30 12:45:37 +00:00

43 lines
1.2 KiB
JavaScript

import Ember from 'ember';
import {request as ajax} from 'ic-ajax';
import Configuration from 'ember-simple-auth/configuration';
import styleBody from 'ghost/mixins/style-body';
const {Route, inject} = Ember;
export default Route.extend(styleBody, {
titleToken: 'Setup',
classNames: ['ghost-setup'],
ghostPaths: inject.service('ghost-paths'),
session: inject.service(),
// use the beforeModel hook to check to see whether or not setup has been
// previously completed. If it has, stop the transition into the setup page.
beforeModel() {
this._super(...arguments);
if (this.get('session.isAuthenticated')) {
this.transitionTo(Configuration.routeIfAlreadyAuthenticated);
return;
}
// If user is not logged in, check the state of the setup process via the API
return ajax(this.get('ghostPaths.url').api('authentication/setup'), {
type: 'GET'
}).then((result) => {
let setup = result.setup[0].status;
if (setup) {
return this.transitionTo('signin');
}
});
},
deactivate() {
this._super(...arguments);
this.controllerFor('setup/two').set('password', '');
}
});