From f06fbd030552c3be53bc8c74f5f23d3cadb3c162 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 16:09:51 -0700 Subject: [PATCH] Inject session for vanilla ajax requests --- app/pods/protected/compare/results/route.js | 4 +++- app/pods/protected/users/changepassword/controller.js | 3 ++- app/pods/users/new/verify/route.js | 4 +++- app/pods/users/requestlockouthelp/controller.js | 4 +++- app/utils/ajax-request.js | 7 ++++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/pods/protected/compare/results/route.js b/app/pods/protected/compare/results/route.js index e37da66..981fa36 100644 --- a/app/pods/protected/compare/results/route.js +++ b/app/pods/protected/compare/results/route.js @@ -2,6 +2,8 @@ import Ember from 'ember'; import ajaxRequest from '../../../../utils/ajax-request'; export default Ember.Route.extend({ + session: Ember.inject.service('session'), + queryParams: { strain_ids: { refreshModel: true, @@ -33,7 +35,7 @@ export default Ember.Route.extend({ method: 'GET', data: params, }; - return ajaxRequest(url, options); + return ajaxRequest(url, options, this.get('session')); }, setupController: function(controller, model) { diff --git a/app/pods/protected/users/changepassword/controller.js b/app/pods/protected/users/changepassword/controller.js index 512c539..3b54073 100644 --- a/app/pods/protected/users/changepassword/controller.js +++ b/app/pods/protected/users/changepassword/controller.js @@ -2,6 +2,7 @@ import Ember from 'ember'; import ajaxRequest from '../../../../utils/ajax-request'; export default Ember.Controller.extend({ + session: Ember.inject.service('session'), currentUser: Ember.inject.service('session-account'), passwordConfirm: null, @@ -22,7 +23,7 @@ export default Ember.Controller.extend({ password: this.get('password'), }, }; - ajaxRequest(url, options); + ajaxRequest(url, options, this.get('session')); this.transitionTo('protected.users.index'); this.get('flashMessages').information('Your password has been changed.'); }, diff --git a/app/pods/users/new/verify/route.js b/app/pods/users/new/verify/route.js index 0593ba8..7c50823 100644 --- a/app/pods/users/new/verify/route.js +++ b/app/pods/users/new/verify/route.js @@ -2,6 +2,8 @@ import Ember from 'ember'; import ajaxRequest from '../../../../utils/ajax-request'; export default Ember.Route.extend({ + session: Ember.inject.service('session'), + apiURL: function() { return this.get('globals.apiURL'); }.property(), @@ -12,7 +14,7 @@ export default Ember.Route.extend({ model: function(params) { let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`; - return ajaxRequest(url); + return ajaxRequest(url, {}, this.get('session')); }, diff --git a/app/pods/users/requestlockouthelp/controller.js b/app/pods/users/requestlockouthelp/controller.js index 205f73c..d138cc6 100644 --- a/app/pods/users/requestlockouthelp/controller.js +++ b/app/pods/users/requestlockouthelp/controller.js @@ -2,6 +2,8 @@ import Ember from 'ember'; import ajaxRequest from '../../../utils/ajax-request'; export default Ember.Controller.extend({ + session: Ember.inject.service('session'), + actions: { save: function() { let url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/lockout`; @@ -9,7 +11,7 @@ export default Ember.Controller.extend({ method: 'POST', data: { email: this.get('email') }, }; - ajaxRequest(url, options); + ajaxRequest(url, options, this.get('session')); this.transitionTo('login'); this.get('flashMessages').information('Please check your email'); }, diff --git a/app/utils/ajax-request.js b/app/utils/ajax-request.js index 30eee5f..a4c8de9 100644 --- a/app/utils/ajax-request.js +++ b/app/utils/ajax-request.js @@ -1,9 +1,14 @@ import Ember from 'ember'; -export default function ajaxRequest(url, options) { +export default function ajaxRequest(url, options, session) { return new Ember.RSVP.Promise(function(resolve, reject) { options = options || {}; options.url = url; + session.authorize('authorizer:application', (headerName, headerValue) => { + let authHeader = {}; + authHeader[headerName] = headerValue; + options.headers = authHeader; + }); options.success = function(data) { resolve(data); };