Inject session for vanilla ajax requests
This commit is contained in:
parent
bbcef5459e
commit
f06fbd0305
5 changed files with 17 additions and 5 deletions
|
@ -2,6 +2,8 @@ import Ember from 'ember';
|
||||||
import ajaxRequest from '../../../../utils/ajax-request';
|
import ajaxRequest from '../../../../utils/ajax-request';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
session: Ember.inject.service('session'),
|
||||||
|
|
||||||
queryParams: {
|
queryParams: {
|
||||||
strain_ids: {
|
strain_ids: {
|
||||||
refreshModel: true,
|
refreshModel: true,
|
||||||
|
@ -33,7 +35,7 @@ export default Ember.Route.extend({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
data: params,
|
data: params,
|
||||||
};
|
};
|
||||||
return ajaxRequest(url, options);
|
return ajaxRequest(url, options, this.get('session'));
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Ember from 'ember';
|
||||||
import ajaxRequest from '../../../../utils/ajax-request';
|
import ajaxRequest from '../../../../utils/ajax-request';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
session: Ember.inject.service('session'),
|
||||||
currentUser: Ember.inject.service('session-account'),
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
passwordConfirm: null,
|
passwordConfirm: null,
|
||||||
|
@ -22,7 +23,7 @@ export default Ember.Controller.extend({
|
||||||
password: this.get('password'),
|
password: this.get('password'),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
ajaxRequest(url, options);
|
ajaxRequest(url, options, this.get('session'));
|
||||||
this.transitionTo('protected.users.index');
|
this.transitionTo('protected.users.index');
|
||||||
this.get('flashMessages').information('Your password has been changed.');
|
this.get('flashMessages').information('Your password has been changed.');
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,8 @@ import Ember from 'ember';
|
||||||
import ajaxRequest from '../../../../utils/ajax-request';
|
import ajaxRequest from '../../../../utils/ajax-request';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
session: Ember.inject.service('session'),
|
||||||
|
|
||||||
apiURL: function() {
|
apiURL: function() {
|
||||||
return this.get('globals.apiURL');
|
return this.get('globals.apiURL');
|
||||||
}.property(),
|
}.property(),
|
||||||
|
@ -12,7 +14,7 @@ export default Ember.Route.extend({
|
||||||
|
|
||||||
model: function(params) {
|
model: function(params) {
|
||||||
let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`;
|
let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`;
|
||||||
return ajaxRequest(url);
|
return ajaxRequest(url, {}, this.get('session'));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ import Ember from 'ember';
|
||||||
import ajaxRequest from '../../../utils/ajax-request';
|
import ajaxRequest from '../../../utils/ajax-request';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
session: Ember.inject.service('session'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save: function() {
|
save: function() {
|
||||||
let url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/lockout`;
|
let url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/lockout`;
|
||||||
|
@ -9,7 +11,7 @@ export default Ember.Controller.extend({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: { email: this.get('email') },
|
data: { email: this.get('email') },
|
||||||
};
|
};
|
||||||
ajaxRequest(url, options);
|
ajaxRequest(url, options, this.get('session'));
|
||||||
this.transitionTo('login');
|
this.transitionTo('login');
|
||||||
this.get('flashMessages').information('Please check your email');
|
this.get('flashMessages').information('Please check your email');
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
import Ember from 'ember';
|
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) {
|
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.url = url;
|
options.url = url;
|
||||||
|
session.authorize('authorizer:application', (headerName, headerValue) => {
|
||||||
|
let authHeader = {};
|
||||||
|
authHeader[headerName] = headerValue;
|
||||||
|
options.headers = authHeader;
|
||||||
|
});
|
||||||
options.success = function(data) {
|
options.success = function(data) {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue