2017-08-22 10:53:26 +03:00
|
|
|
import Route from '@ember/routing/route';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2014-06-25 16:12:48 +04:00
|
|
|
|
2019-05-20 16:57:21 +03:00
|
|
|
export default Route.extend({
|
2017-10-30 12:38:01 +03:00
|
|
|
ghostPaths: service(),
|
|
|
|
session: service(),
|
|
|
|
ajax: service(),
|
|
|
|
config: service(),
|
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() {
|
2015-11-15 14:06:49 +03:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2017-09-04 22:17:04 +03:00
|
|
|
if (this.get('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
|
|
|
|
2016-01-18 18:37:14 +03:00
|
|
|
let authUrl = this.get('ghostPaths.url').api('authentication', 'setup');
|
|
|
|
|
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 {
|
|
|
|
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);
|
|
|
|
}
|
2016-01-18 18:37:14 +03:00
|
|
|
}
|
|
|
|
});
|
2015-08-25 12:54:39 +03:00
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
deactivate() {
|
|
|
|
this._super(...arguments);
|
2015-08-25 12:54:39 +03:00
|
|
|
this.controllerFor('setup/two').set('password', '');
|
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
|
|
|
}
|
2014-06-25 16:12:48 +04:00
|
|
|
});
|