parent
e54c6fcb2f
commit
b12ff0eb20
7 changed files with 34 additions and 51 deletions
|
@ -1,10 +1,10 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import ajaxRequest from '../../../../utils/ajax-request';
|
|
||||||
|
|
||||||
const { Route, $: { isEmptyObject }, inject: { service } } = Ember;
|
const { Route, $: { isEmptyObject }, inject: { service } } = Ember;
|
||||||
|
|
||||||
export default Route.extend({
|
export default Route.extend({
|
||||||
session: service(),
|
session: service(),
|
||||||
|
ajax: service(),
|
||||||
|
|
||||||
queryParams: {
|
queryParams: {
|
||||||
strain_ids: {
|
strain_ids: {
|
||||||
|
@ -33,12 +33,7 @@ export default Route.extend({
|
||||||
compare.set('selectedStrains', params.strain_ids);
|
compare.set('selectedStrains', params.strain_ids);
|
||||||
compare.set('selectedCharacteristics', params.characteristic_ids);
|
compare.set('selectedCharacteristics', params.characteristic_ids);
|
||||||
|
|
||||||
const url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/compare`;
|
return this.get('ajax').request('/compare', { data: params })
|
||||||
const options = {
|
|
||||||
method: 'GET',
|
|
||||||
data: params,
|
|
||||||
};
|
|
||||||
return ajaxRequest(url, options, this.get('session'));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
|
|
|
@ -1,24 +1,17 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import ajaxRequest from '../../../../utils/ajax-request';
|
|
||||||
|
|
||||||
const { Controller, inject: { service } } = Ember;
|
const { Controller, inject: { service } } = Ember;
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
session: service(),
|
session: service(),
|
||||||
|
ajax: service(),
|
||||||
currentUser: service('session-account'),
|
currentUser: service('session-account'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save: function(password) {
|
save: function(password) {
|
||||||
const url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/password`;
|
|
||||||
const id = this.get('currentUser.account.id');
|
const id = this.get('currentUser.account.id');
|
||||||
const options = {
|
const data = { id: id, password: password };
|
||||||
method: 'POST',
|
this.get('ajax').post('/users/password', { data: data });
|
||||||
data: {
|
|
||||||
id: id,
|
|
||||||
password: password,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
ajaxRequest(url, options, this.get('session'));
|
|
||||||
this.transitionToRoute('protected.users.show', id);
|
this.transitionToRoute('protected.users.show', id);
|
||||||
this.get('flashMessages').information('Your password has been changed.');
|
this.get('flashMessages').information('Your password has been changed.');
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,20 +1,17 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import ajaxRequest from '../../../../utils/ajax-request';
|
|
||||||
|
|
||||||
const { Route, inject: { service } } = Ember;
|
const { Route, inject: { service } } = Ember;
|
||||||
|
|
||||||
export default Route.extend({
|
export default Route.extend({
|
||||||
session: service(),
|
session: service(),
|
||||||
globals: service(),
|
ajax: service(),
|
||||||
|
|
||||||
model: function(params) {
|
model: function(params) {
|
||||||
const url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/verify/${params.nonce}`;
|
return this.get('ajax').request(`/users/verify/${params.nonce}`);
|
||||||
return ajaxRequest(url, {}, this.get('session'));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
afterModel: function(model/*, transition*/) {
|
afterModel: function(model/*, transition*/) {
|
||||||
this.get('flashMessages').success(model.get('msg'));
|
this.get('flashMessages').success(model.msg);
|
||||||
this.transitionTo('login');
|
this.transitionTo('login');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import ajaxRequest from '../../../utils/ajax-request';
|
|
||||||
|
|
||||||
const { Controller, inject: { service } } = Ember;
|
const { Controller, inject: { service } } = Ember;
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
session: service(),
|
session: service(),
|
||||||
globals: service(),
|
globals: service(),
|
||||||
|
ajax: service(),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
submit: function(email) {
|
submit: function(email) {
|
||||||
const url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/lockout`;
|
this.get('ajax').post('/users/lockout', { data: { email: email } } );
|
||||||
const options = {
|
|
||||||
method: 'POST',
|
|
||||||
data: { email: email },
|
|
||||||
};
|
|
||||||
ajaxRequest(url, options, this.get('session'));
|
|
||||||
this.transitionToRoute('login');
|
this.transitionToRoute('login');
|
||||||
this.get('flashMessages').information('Please check your email');
|
this.get('flashMessages').information('Please check your email');
|
||||||
},
|
},
|
||||||
|
|
23
app/services/ajax.js
Normal file
23
app/services/ajax.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
import AjaxService from 'ember-ajax/services/ajax';
|
||||||
|
|
||||||
|
const { computed, inject: { service } } = Ember;
|
||||||
|
|
||||||
|
export default AjaxService.extend({
|
||||||
|
session: service(),
|
||||||
|
globals: service(),
|
||||||
|
|
||||||
|
host: computed('globals.apiURL', function() {
|
||||||
|
return `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}`;
|
||||||
|
}),
|
||||||
|
|
||||||
|
headers: computed('session.authToken', {
|
||||||
|
get: function() {
|
||||||
|
let headers = {};
|
||||||
|
this.get('session').authorize('authorizer:application', (headerName, headerValue) => {
|
||||||
|
headers[headerName] = headerValue;
|
||||||
|
});
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
|
@ -1,20 +0,0 @@
|
||||||
import Ember from 'ember';
|
|
||||||
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
options.error = function(jqXHR, status, error) {
|
|
||||||
reject(jqXHR, status, error);
|
|
||||||
};
|
|
||||||
Ember.$.ajax(options);
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -28,7 +28,7 @@
|
||||||
"ember-cli-flash": "1.3.6",
|
"ember-cli-flash": "1.3.6",
|
||||||
"ember-cli-htmlbars": "^1.0.1",
|
"ember-cli-htmlbars": "^1.0.1",
|
||||||
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
|
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
|
||||||
"ember-cli-ic-ajax": "0.2.1",
|
"ember-ajax": "0.7.0",
|
||||||
"ember-cli-inject-live-reload": "^1.3.1",
|
"ember-cli-inject-live-reload": "^1.3.1",
|
||||||
"ember-cli-mirage": "0.1.11",
|
"ember-cli-mirage": "0.1.11",
|
||||||
"ember-cli-qunit": "^1.0.4",
|
"ember-cli-qunit": "^1.0.4",
|
||||||
|
|
Reference in a new issue