2016-06-30 13:21:47 +03:00
|
|
|
import Route from 'ember-route';
|
|
|
|
import injectService from 'ember-service/inject';
|
2016-05-24 15:06:59 +03:00
|
|
|
import styleBody from 'ghost-admin/mixins/style-body';
|
2014-06-25 16:12:48 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
export default Route.extend(styleBody, {
|
2014-11-25 23:56:08 +03:00
|
|
|
titleToken: 'Setup',
|
|
|
|
|
2014-07-01 14:57:44 +04:00
|
|
|
classNames: ['ghost-setup'],
|
2014-07-15 23:52:44 +04:00
|
|
|
|
2016-06-30 13:21:47 +03:00
|
|
|
ghostPaths: injectService(),
|
|
|
|
session: injectService(),
|
|
|
|
ajax: injectService(),
|
2016-09-30 14:43:40 +03:00
|
|
|
config: injectService(),
|
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);
|
|
|
|
|
2016-09-30 14:43:40 +03:00
|
|
|
// with OAuth auth users are authenticated on step 2 so we
|
|
|
|
// can't use the session.isAuthenticated shortcut
|
|
|
|
if (!this.get('config.ghostOAuth') && this.get('session.isAuthenticated')) {
|
2017-02-06 18:53:04 +03:00
|
|
|
this.transitionTo('posts');
|
2014-07-15 23:52:44 +04:00
|
|
|
return;
|
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
|
2016-01-18 18:37:14 +03:00
|
|
|
return this.get('ajax').request(authUrl)
|
|
|
|
.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', '');
|
2014-07-01 14:57:44 +04:00
|
|
|
}
|
2014-06-25 16:12:48 +04:00
|
|
|
});
|