Ghost/ghost/admin/app/routes/setup.js
Kevin Ansfield a258e3d881 Ghost.org OAuth support (#278)
issue TryGhost/Ghost#7452, requires TryGhost/Ghost#7451
- use a `ghostOAuth` config flag to switch between the old-style per-install auth and centralized OAuth auth based on config provided by the server
- add OAuth flows for:
  - setup
  - sign-in
  - sign-up
  - re-authenticate
- add custom `oauth-ghost` authenticator to support our custom data structure
- add test helpers to stub successful/failed oauth authentication
- hide change password form if using OAuth (temporary - a way to change password via oauth provider will be added later)
2016-09-30 13:43:40 +02:00

59 lines
2.0 KiB
JavaScript

import Route from 'ember-route';
import injectService from 'ember-service/inject';
import Configuration from 'ember-simple-auth/configuration';
import styleBody from 'ghost-admin/mixins/style-body';
export default Route.extend(styleBody, {
titleToken: 'Setup',
classNames: ['ghost-setup'],
ghostPaths: injectService(),
session: injectService(),
ajax: injectService(),
config: injectService(),
// 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.
beforeModel() {
this._super(...arguments);
// 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')) {
this.transitionTo(Configuration.routeIfAlreadyAuthenticated);
return;
}
let authUrl = this.get('ghostPaths.url').api('authentication', 'setup');
// check the state of the setup process via the API
return this.get('ajax').request(authUrl)
.then((result) => {
let [setup] = result.setup;
if (setup.status) {
return this.transitionTo('signin');
} 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);
}
}
});
},
deactivate() {
this._super(...arguments);
this.controllerFor('setup/two').set('password', '');
}
});