From 7835d824d39246492def92b51147d8bbd0ae3967 Mon Sep 17 00:00:00 2001 From: Marco Otte-Witte Date: Fri, 25 Jul 2014 15:38:13 +0200 Subject: [PATCH] updated Ember Simple Auth to latest version --- ghost/admin/.jshintrc | 1 + ghost/admin/controllers/setup.js | 4 ++-- ghost/admin/controllers/signin.js | 4 ++-- ghost/admin/controllers/signup.js | 4 ++-- ghost/admin/initializers/authentication.js | 22 ++++++++++++---------- ghost/admin/routes/application.js | 2 +- ghost/admin/routes/debug.js | 2 +- ghost/admin/routes/editor/edit.js | 2 +- ghost/admin/routes/editor/new.js | 2 +- ghost/admin/routes/posts.js | 2 +- ghost/admin/routes/posts/index.js | 2 +- ghost/admin/routes/posts/post.js | 2 +- ghost/admin/routes/settings.js | 2 +- ghost/admin/routes/settings/apps.js | 2 +- ghost/admin/routes/settings/general.js | 2 +- ghost/admin/routes/settings/index.js | 2 +- ghost/admin/routes/settings/users.js | 2 +- ghost/admin/routes/settings/users/index.js | 2 +- ghost/admin/routes/setup.js | 2 +- ghost/admin/routes/signin.js | 4 ++-- ghost/admin/routes/signout.js | 4 ++-- ghost/admin/routes/signup.js | 2 +- 22 files changed, 38 insertions(+), 35 deletions(-) diff --git a/ghost/admin/.jshintrc b/ghost/admin/.jshintrc index 5574b02288..6c97bb92f7 100644 --- a/ghost/admin/.jshintrc +++ b/ghost/admin/.jshintrc @@ -27,6 +27,7 @@ "Em": true, "DS": true, "$": true, + "SimpleAuth": true, "validator": true, "ic": true, "_": true, diff --git a/ghost/admin/controllers/setup.js b/ghost/admin/controllers/setup.js index 4e49f20ed0..bffbfbdb9c 100644 --- a/ghost/admin/controllers/setup.js +++ b/ghost/admin/controllers/setup.js @@ -32,12 +32,12 @@ var SetupController = Ember.ObjectController.extend(ValidationEngine, { }] } }).then(function () { - self.get('session').authenticate('ember-simple-auth-authenticator:oauth2-password-grant', { + self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', { identification: self.get('email'), password: self.get('password') }).then(function () { self.send('signedIn'); - self.transitionToRoute(Ember.SimpleAuth.routeAfterAuthentication); + self.transitionToRoute(SimpleAuth.Configuration.routeAfterAuthentication); }); }, function (resp) { self.toggleProperty('submitting'); diff --git a/ghost/admin/controllers/signin.js b/ghost/admin/controllers/signin.js index 4f7993303d..65f549f817 100644 --- a/ghost/admin/controllers/signin.js +++ b/ghost/admin/controllers/signin.js @@ -1,7 +1,7 @@ import ValidationEngine from 'ghost/mixins/validation-engine'; -var SigninController = Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin, ValidationEngine, { - authenticatorFactory: 'ember-simple-auth-authenticator:oauth2-password-grant', +var SigninController = Ember.Controller.extend(SimpleAuth.LoginControllerMixin, ValidationEngine, { + authenticator: 'simple-auth-authenticator:oauth2-password-grant', validationType: 'signin', diff --git a/ghost/admin/controllers/signup.js b/ghost/admin/controllers/signup.js index e87ecc71eb..3c2af6e310 100644 --- a/ghost/admin/controllers/signup.js +++ b/ghost/admin/controllers/signup.js @@ -33,12 +33,12 @@ var SignupController = Ember.ObjectController.extend(ValidationEngine, { }] } }).then(function () { - self.get('session').authenticate('ember-simple-auth-authenticator:oauth2-password-grant', { + self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', { identification: self.get('email'), password: self.get('password') }).then(function () { self.send('signedIn'); - self.transitionToRoute(Ember.SimpleAuth.routeAfterAuthentication); + self.transitionToRoute(SimpleAuth.Configuration.routeAfterAuthentication); }); }, function (resp) { self.toggleProperty('submitting'); diff --git a/ghost/admin/initializers/authentication.js b/ghost/admin/initializers/authentication.js index 660dda7649..aa604a21dd 100644 --- a/ghost/admin/initializers/authentication.js +++ b/ghost/admin/initializers/authentication.js @@ -1,27 +1,29 @@ var AuthenticationInitializer = { name: 'authentication', + before: 'simple-auth', after: 'registerTrailingLocationHistory', - initialize: function (container, application) { - Ember.SimpleAuth.Session.reopen({ + initialize: function (container) { + window.ENV = window.ENV || {}; + window.ENV['simple-auth'] = { + authenticationRoute: 'signin', + routeAfterAuthentication: 'content', + authorizer: 'simple-auth-authorizer:oauth2-bearer' + }; + SimpleAuth.Session.reopen({ user: function () { return container.lookup('store:main').find('user', 'me'); }.property() }); - Ember.SimpleAuth.Authenticators.OAuth2.reopen({ + SimpleAuth.Authenticators.OAuth2.reopen({ serverTokenEndpoint: '/ghost/api/v0.1/authentication/token', refreshAccessTokens: true, - makeRequest: function (data) { + makeRequest: function (url, data) { data.client_id = 'ghost-admin'; - return this._super(data); + return this._super(url, data); } }); - Ember.SimpleAuth.setup(container, application, { - authenticationRoute: 'signin', - routeAfterAuthentication: 'content', - authorizerFactory: 'ember-simple-auth-authorizer:oauth2-bearer' - }); } }; diff --git a/ghost/admin/routes/application.js b/ghost/admin/routes/application.js index 6e24038f29..00904d5927 100644 --- a/ghost/admin/routes/application.js +++ b/ghost/admin/routes/application.js @@ -1,6 +1,6 @@ import ShortcutsRoute from 'ghost/mixins/shortcuts-route'; -var ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin, ShortcutsRoute, { +var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, ShortcutsRoute, { shortcuts: { 'esc': 'closePopups' diff --git a/ghost/admin/routes/debug.js b/ghost/admin/routes/debug.js index 4a9949b7a7..d14e376bee 100644 --- a/ghost/admin/routes/debug.js +++ b/ghost/admin/routes/debug.js @@ -1,7 +1,7 @@ import styleBody from 'ghost/mixins/style-body'; import loadingIndicator from 'ghost/mixins/loading-indicator'; -var DebugRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, styleBody, loadingIndicator, { +var DebugRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, styleBody, loadingIndicator, { classNames: ['settings'], beforeModel: function () { diff --git a/ghost/admin/routes/editor/edit.js b/ghost/admin/routes/editor/edit.js index d1b5e911a4..9bcdfa35b6 100644 --- a/ghost/admin/routes/editor/edit.js +++ b/ghost/admin/routes/editor/edit.js @@ -1,6 +1,6 @@ import base from 'ghost/mixins/editor-route-base'; -var EditorEditRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, base, { +var EditorEditRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, base, { classNames: ['editor'], model: function (params) { diff --git a/ghost/admin/routes/editor/new.js b/ghost/admin/routes/editor/new.js index 6eee9eadc9..7b3bfeff55 100644 --- a/ghost/admin/routes/editor/new.js +++ b/ghost/admin/routes/editor/new.js @@ -1,6 +1,6 @@ import base from 'ghost/mixins/editor-route-base'; -var EditorNewRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, base, { +var EditorNewRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, base, { classNames: ['editor'], model: function () { diff --git a/ghost/admin/routes/posts.js b/ghost/admin/routes/posts.js index 1e9ee4b54e..877f1adf80 100644 --- a/ghost/admin/routes/posts.js +++ b/ghost/admin/routes/posts.js @@ -9,7 +9,7 @@ var paginationSettings = { page: 1 }; -var PostsRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, ShortcutsRoute, styleBody, loadingIndicator, PaginationRouteMixin, { +var PostsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, ShortcutsRoute, styleBody, loadingIndicator, PaginationRouteMixin, { classNames: ['manage'], model: function () { diff --git a/ghost/admin/routes/posts/index.js b/ghost/admin/routes/posts/index.js index acd5ec2578..482584631f 100644 --- a/ghost/admin/routes/posts/index.js +++ b/ghost/admin/routes/posts/index.js @@ -1,6 +1,6 @@ import loadingIndicator from 'ghost/mixins/loading-indicator'; -var PostsIndexRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, { +var PostsIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, { // This route's only function is to determine whether or not a post // exists to be used for the content preview. It has a parent resource (Posts) // that is responsible for populating the store. diff --git a/ghost/admin/routes/posts/post.js b/ghost/admin/routes/posts/post.js index 7d372340ad..99738b26fb 100644 --- a/ghost/admin/routes/posts/post.js +++ b/ghost/admin/routes/posts/post.js @@ -1,7 +1,7 @@ import loadingIndicator from 'ghost/mixins/loading-indicator'; import ShortcutsRoute from 'ghost/mixins/shortcuts-route'; -var PostsPostRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, ShortcutsRoute, { +var PostsPostRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, ShortcutsRoute, { model: function (params) { var self = this, post, diff --git a/ghost/admin/routes/settings.js b/ghost/admin/routes/settings.js index 1703d63a7d..2543ff9f69 100644 --- a/ghost/admin/routes/settings.js +++ b/ghost/admin/routes/settings.js @@ -1,7 +1,7 @@ import styleBody from 'ghost/mixins/style-body'; import loadingIndicator from 'ghost/mixins/loading-indicator'; -var SettingsRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, styleBody, loadingIndicator, { +var SettingsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, styleBody, loadingIndicator, { classNames: ['settings'] }); diff --git a/ghost/admin/routes/settings/apps.js b/ghost/admin/routes/settings/apps.js index f0bda6b86b..9672c1bc54 100644 --- a/ghost/admin/routes/settings/apps.js +++ b/ghost/admin/routes/settings/apps.js @@ -1,4 +1,4 @@ -var AppsRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, { +var AppsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, { beforeModel: function () { if (!this.get('config.apps')) { this.transitionTo('settings.general'); diff --git a/ghost/admin/routes/settings/general.js b/ghost/admin/routes/settings/general.js index c1fd5f830f..5843e28e2e 100644 --- a/ghost/admin/routes/settings/general.js +++ b/ghost/admin/routes/settings/general.js @@ -1,6 +1,6 @@ import loadingIndicator from 'ghost/mixins/loading-indicator'; -var SettingsGeneralRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, { +var SettingsGeneralRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, { model: function () { return this.store.find('setting', { type: 'blog,theme' }).then(function (records) { return records.get('firstObject'); diff --git a/ghost/admin/routes/settings/index.js b/ghost/admin/routes/settings/index.js index 3c90352756..09b42bfeb8 100644 --- a/ghost/admin/routes/settings/index.js +++ b/ghost/admin/routes/settings/index.js @@ -1,6 +1,6 @@ import {mobileQuery} from 'ghost/utils/mobile'; -var SettingsIndexRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, { +var SettingsIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, { // redirect to general tab, unless on a mobile phone beforeModel: function () { if (!mobileQuery.matches) { diff --git a/ghost/admin/routes/settings/users.js b/ghost/admin/routes/settings/users.js index 02bfbc91cd..e449f30085 100644 --- a/ghost/admin/routes/settings/users.js +++ b/ghost/admin/routes/settings/users.js @@ -1,3 +1,3 @@ -var UsersRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin); +var UsersRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin); export default UsersRoute; diff --git a/ghost/admin/routes/settings/users/index.js b/ghost/admin/routes/settings/users/index.js index 55fbda565c..a698134226 100644 --- a/ghost/admin/routes/settings/users/index.js +++ b/ghost/admin/routes/settings/users/index.js @@ -6,7 +6,7 @@ var paginationSettings = { status: 'all' }; -var UsersIndexRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, PaginationRouteMixin, { +var UsersIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, PaginationRouteMixin, { setupController: function (controller, model) { this._super(controller, model); this.setupPagination(paginationSettings); diff --git a/ghost/admin/routes/setup.js b/ghost/admin/routes/setup.js index 29093c5eea..65ec5ffc25 100644 --- a/ghost/admin/routes/setup.js +++ b/ghost/admin/routes/setup.js @@ -12,7 +12,7 @@ var SetupRoute = Ember.Route.extend(styleBody, loadingIndicator, { // If user is logged in, setup has already been completed. if (this.get('session').isAuthenticated) { - this.transitionTo(Ember.SimpleAuth.routeAfterAuthentication); + this.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication); return; } diff --git a/ghost/admin/routes/signin.js b/ghost/admin/routes/signin.js index b10d5ee2a6..87e6691628 100644 --- a/ghost/admin/routes/signin.js +++ b/ghost/admin/routes/signin.js @@ -5,7 +5,7 @@ var SigninRoute = Ember.Route.extend(styleBody, loadingIndicator, { classNames: ['ghost-login'], beforeModel: function () { if (this.get('session').isAuthenticated) { - this.transitionTo(Ember.SimpleAuth.routeAfterAuthentication); + this.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication); } }, actions: { @@ -22,7 +22,7 @@ var SigninRoute = Ember.Route.extend(styleBody, loadingIndicator, { attemptedTransition.retry(); self.get('session').set('attemptedTransition', null); } else { - self.transitionTo(Ember.SimpleAuth.routeAfterAuthentication); + self.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication); } }); }, diff --git a/ghost/admin/routes/signout.js b/ghost/admin/routes/signout.js index 33f255c8ed..f6ed18472d 100644 --- a/ghost/admin/routes/signout.js +++ b/ghost/admin/routes/signout.js @@ -1,13 +1,13 @@ import styleBody from 'ghost/mixins/style-body'; import loadingIndicator from 'ghost/mixins/loading-indicator'; -var SignoutRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, styleBody, loadingIndicator, { +var SignoutRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, styleBody, loadingIndicator, { classNames: ['ghost-signout'], afterModel: function (resolvedModel, transition) { if (Ember.canInvoke(transition, 'send')) { - transition.abort(); transition.send('invalidateSession'); + transition.abort(); this.transitionTo('signin'); } else { this.send('invalidateSession'); diff --git a/ghost/admin/routes/signup.js b/ghost/admin/routes/signup.js index 1dd1807671..a18c59c5a0 100644 --- a/ghost/admin/routes/signup.js +++ b/ghost/admin/routes/signup.js @@ -5,7 +5,7 @@ var SignupRoute = Ember.Route.extend(styleBody, loadingIndicator, { classNames: ['ghost-signup'], beforeModel: function () { if (this.get('session').isAuthenticated) { - this.transitionTo(Ember.SimpleAuth.routeAfterAuthentication); + this.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication); } }, setupController: function (controller, params) {