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-10-18 21:17:02 +03:00
|
|
|
import Configuration from 'ember-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'),
|
2015-10-18 21:17:02 +03:00
|
|
|
session: Ember.inject.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.
|
2014-07-01 14:57:44 +04:00
|
|
|
beforeModel: function () {
|
2014-07-15 23:52:44 +04:00
|
|
|
var self = this;
|
|
|
|
|
2015-10-18 21:17:02 +03:00
|
|
|
if (this.get('session.isAuthenticated')) {
|
|
|
|
this.transitionTo(Configuration.routeIfAlreadyAuthenticated);
|
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');
|
|
|
|
}
|
|
|
|
});
|
2015-08-25 12:54:39 +03:00
|
|
|
},
|
|
|
|
deactivate: function () {
|
|
|
|
this._super();
|
|
|
|
this.controllerFor('setup/two').set('password', '');
|
2014-07-01 14:57:44 +04:00
|
|
|
}
|
2014-06-25 16:12:48 +04:00
|
|
|
});
|