Ghost/ghost/admin/app/routes/setup.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

import Route from '@ember/routing/route';
import {inject as service} from '@ember/service';
export default class SetupRoute extends Route {
@service ghostPaths;
@service session;
@service ajax;
@service config;
// 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() {
super.beforeModel(...arguments);
if (this.session.isAuthenticated) {
return this.transitionTo('home');
}
let authUrl = this.ghostPaths.url.api('authentication', 'setup');
2016-01-18 18:37:14 +03:00
// check the state of the setup process via the API
return this.ajax.request(authUrl)
2016-01-18 18:37:14 +03:00
.then((result) => {
let [setup] = result.setup;
2016-01-18 18:37:14 +03:00
if (setup.status) {
2016-01-18 18:37:14 +03:00
return this.transitionTo('signin');
} else {
let controller = this.controllerFor('setup');
if (setup.title) {
controller.set('blogTitle', setup.title.replace(/'/gim, '\''));
}
if (setup.name) {
controller.set('name', setup.name.replace(/'/gim, '\''));
}
if (setup.email) {
controller.set('email', setup.email);
}
2016-01-18 18:37:14 +03:00
}
});
}
deactivate() {
super.deactivate(...arguments);
this.controllerFor('setup').set('password', '');
}
buildRouteInfoMetadata() {
return {
titleToken: 'Setup',
bodyClasses: ['unauthenticated-route'],
mainClasses: ['gh-main-white']
};
}
}