2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2015-05-27 03:41:12 +03:00
|
|
|
import {request as ajax} from 'ic-ajax';
|
2015-05-13 08:27:59 +03:00
|
|
|
import Configuration from 'simple-auth/configuration';
|
2014-06-25 16:12:48 +04:00
|
|
|
import styleBody from 'ghost/mixins/style-body';
|
|
|
|
|
2015-05-27 03:41:12 +03:00
|
|
|
export default Ember.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
|
|
|
|
2015-05-26 05:10:50 +03:00
|
|
|
ghostPaths: Ember.inject.service('ghost-paths'),
|
|
|
|
|
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.
|
2014-07-01 14:57:44 +04:00
|
|
|
beforeModel: function () {
|
2014-07-15 23:52:44 +04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// If user is logged in, setup has already been completed.
|
2014-07-01 14:57:44 +04:00
|
|
|
if (this.get('session').isAuthenticated) {
|
2015-05-13 08:27:59 +03:00
|
|
|
this.transitionTo(Configuration.routeAfterAuthentication);
|
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
|
|
|
|
|
|
|
// If user is not logged in, check the state of the setup process via the API
|
2015-05-27 03:41:12 +03:00
|
|
|
return ajax(this.get('ghostPaths.url').api('authentication/setup'), {
|
2014-07-15 23:52:44 +04:00
|
|
|
type: 'GET'
|
|
|
|
}).then(function (result) {
|
|
|
|
var setup = result.setup[0].status;
|
|
|
|
|
|
|
|
if (setup) {
|
|
|
|
return self.transitionTo('signin');
|
|
|
|
}
|
|
|
|
});
|
2014-07-01 14:57:44 +04:00
|
|
|
}
|
2014-06-25 16:12:48 +04:00
|
|
|
});
|