2017-08-22 10:53:26 +03:00
|
|
|
import Route from '@ember/routing/route';
|
2022-11-03 14:14:36 +03:00
|
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2014-06-25 16:12:48 +04:00
|
|
|
|
2022-01-17 12:34:55 +03:00
|
|
|
export default class SetupRoute extends Route {
|
|
|
|
@service ghostPaths;
|
|
|
|
@service session;
|
|
|
|
@service ajax;
|
2022-11-03 14:14:36 +03:00
|
|
|
|
|
|
|
@inject config;
|
2015-05-26 05:10:50 +03:00
|
|
|
|
2014-07-15 23:52:44 +04:00
|
|
|
// 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.
|
2015-10-28 14:36:45 +03:00
|
|
|
beforeModel() {
|
2022-01-17 12:34:55 +03:00
|
|
|
super.beforeModel(...arguments);
|
2015-11-15 14:06:49 +03:00
|
|
|
|
2022-01-17 12:34:55 +03:00
|
|
|
if (this.session.isAuthenticated) {
|
2019-03-21 12:33:14 +03:00
|
|
|
return this.transitionTo('home');
|
2014-07-01 14:57:44 +04:00
|
|
|
}
|
2014-07-15 23:52:44 +04:00
|
|
|
|
2022-01-17 12:34:55 +03:00
|
|
|
let authUrl = this.ghostPaths.url.api('authentication', 'setup');
|
2016-01-18 18:37:14 +03:00
|
|
|
|
2016-09-30 14:43:40 +03:00
|
|
|
// check the state of the setup process via the API
|
2019-03-06 16:53:54 +03:00
|
|
|
return this.ajax.request(authUrl)
|
2016-01-18 18:37:14 +03:00
|
|
|
.then((result) => {
|
2016-05-11 19:44:47 +03:00
|
|
|
let [setup] = result.setup;
|
2016-01-18 18:37:14 +03:00
|
|
|
|
2016-05-11 19:44:47 +03:00
|
|
|
if (setup.status) {
|
2016-01-18 18:37:14 +03:00
|
|
|
return this.transitionTo('signin');
|
2016-05-11 19:44:47 +03:00
|
|
|
} else {
|
2022-03-08 20:30:46 +03:00
|
|
|
let controller = this.controllerFor('setup');
|
2016-05-11 19:44:47 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2022-01-17 12:34:55 +03:00
|
|
|
}
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
deactivate() {
|
2022-01-17 12:34:55 +03:00
|
|
|
super.deactivate(...arguments);
|
2022-03-08 20:30:46 +03:00
|
|
|
this.controllerFor('setup').set('password', '');
|
2022-01-17 12:34:55 +03:00
|
|
|
}
|
2019-05-20 16:57:21 +03:00
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
2019-05-20 18:16:19 +03:00
|
|
|
titleToken: 'Setup',
|
2019-06-18 13:47:21 +03:00
|
|
|
bodyClasses: ['unauthenticated-route'],
|
|
|
|
mainClasses: ['gh-main-white']
|
2019-05-20 16:57:21 +03:00
|
|
|
};
|
2014-07-01 14:57:44 +04:00
|
|
|
}
|
2022-01-17 12:34:55 +03:00
|
|
|
}
|