Ghost/ghost/admin/app/routes/setup.js
Kevin Ansfield 75abe76346 Migrated route objects to native class syntax
no issue

- ran the `ember-native-class-codemod` codemod to convert just the route classes to native class syntax and performed some minor manual cleanup
  - modern Ember uses native classes rather than EmberObject-based objects, this brings us closer to normalizing our code style across the codebase
- skipped the Application route as that requires deeper testing with a replacement for the `ShortcutsRoute` mixin
2022-01-17 10:06:57 +00:00

58 lines
1.7 KiB
JavaScript

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');
// check the state of the setup process via the API
return this.ajax.request(authUrl)
.then((result) => {
let [setup] = result.setup;
if (setup.status) {
return this.transitionTo('signin');
} else {
let controller = this.controllerFor('setup/two');
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);
}
}
});
}
deactivate() {
super.deactivate(...arguments);
this.controllerFor('setup/two').set('password', '');
}
buildRouteInfoMetadata() {
return {
titleToken: 'Setup',
bodyClasses: ['unauthenticated-route'],
mainClasses: ['gh-main-white']
};
}
}