diff --git a/app/authenticators/oauth2.js b/app/authenticators/oauth2.js
new file mode 100644
index 0000000..c5c9221
--- /dev/null
+++ b/app/authenticators/oauth2.js
@@ -0,0 +1,6 @@
+import OAuth2PasswordGrant from 'ember-simple-auth/authenticators/oauth2-password-grant';
+import config from '../config/environment';
+
+export default OAuth2PasswordGrant.extend({
+ serverTokenEndpoint: `${config.apiURL}/api/authenticate`,
+});
diff --git a/app/authorizers/application.js b/app/authorizers/application.js
new file mode 100644
index 0000000..68755e3
--- /dev/null
+++ b/app/authorizers/application.js
@@ -0,0 +1,3 @@
+import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer';
+
+export default OAuth2Bearer.extend({});
diff --git a/app/initializers/custom-session.js b/app/initializers/custom-session.js
deleted file mode 100644
index 011cd90..0000000
--- a/app/initializers/custom-session.js
+++ /dev/null
@@ -1,9 +0,0 @@
-export function initialize(container, application) {
- application.inject('session:custom', '_store', 'service:store');
-}
-
-export default {
- name: 'custom-session',
- after: 'ember-data',
- initialize: initialize
-};
diff --git a/app/models/user.js b/app/models/user.js
index c6a5dac..198f451 100644
--- a/app/models/user.js
+++ b/app/models/user.js
@@ -1,3 +1,4 @@
+import Ember from 'ember';
import DS from 'ember-data';
export default DS.Model.extend({
@@ -33,4 +34,13 @@ export default DS.Model.extend({
return 'Error';
}
}.property('role'),
+
+ canWrite: Ember.computed('role', function() {
+ return this.get('role') !== 'R';
+ }),
+
+ metaData: Ember.computed('canWrite', function() {
+ return { 'canAdd': this.get('canWrite') };
+ }),
+
});
diff --git a/app/pods/application/adapter.js b/app/pods/application/adapter.js
index 11498d0..96daa1a 100644
--- a/app/pods/application/adapter.js
+++ b/app/pods/application/adapter.js
@@ -1,6 +1,9 @@
import DS from 'ember-data';
+import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
+
+export default DS.RESTAdapter.extend(DataAdapterMixin, {
+ authorizer: 'authorizer:application',
-export default DS.RESTAdapter.extend({
namespace: function() {
return 'api/' + this.get('globals.genus');
}.property(),
diff --git a/app/pods/application/route.js b/app/pods/application/route.js
index 0754183..ca03050 100644
--- a/app/pods/application/route.js
+++ b/app/pods/application/route.js
@@ -1,5 +1,5 @@
import Ember from 'ember';
-import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
+import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {
diff --git a/app/pods/components/x-application/component.js b/app/pods/components/x-application/component.js
index 27c8d25..967b497 100644
--- a/app/pods/components/x-application/component.js
+++ b/app/pods/components/x-application/component.js
@@ -3,6 +3,9 @@ import Ember from 'ember';
export default Ember.Component.extend({
classNames: ["flakes-frame"],
+ session: Ember.inject.service('session'),
+ currentUser: Ember.inject.service('session-account'),
+
didInsertElement: function() {
FlakesFrame.init();
},
diff --git a/app/pods/components/x-application/template.hbs b/app/pods/components/x-application/template.hbs
index e859890..49cc38e 100644
--- a/app/pods/components/x-application/template.hbs
+++ b/app/pods/components/x-application/template.hbs
@@ -14,7 +14,7 @@
{{#link-to 'protected.characteristics' tagName='li' href=false}}
{{link-to 'Characteristics' 'protected.characteristics'}}
{{/link-to}}
- {{#if session.currentUser.isAdmin}}
+ {{#if currentUser.account.isAdmin}}
{{#link-to 'protected.users' tagName='li' href=false}}
{{link-to 'Users' 'protected.users'}}
{{/link-to}}
@@ -24,7 +24,7 @@
{{/link-to}}
{{else}}
diff --git a/app/pods/login/controller.js b/app/pods/login/controller.js
index 42e761d..13eed49 100644
--- a/app/pods/login/controller.js
+++ b/app/pods/login/controller.js
@@ -1,21 +1,21 @@
import Ember from 'ember';
export default Ember.Controller.extend({
+ session: Ember.inject.service('session'),
+
loading: false,
actions: {
authenticate: function() {
- let credentials = this.getProperties('identification', 'password');
- let session = this.get('session');
- let authenticator = 'simple-auth-authenticator:jwt';
-
// Manually clean up because there might not be a transition
this.get('flashMessages').clearMessages();
- this.set('loading', true).then(session.authenticate(authenticator, credentials).catch((error) => {
+ let { identification, password } = this.getProperties('identification', 'password');
+ this.set('loading', true)
+ this.get('session').authenticate('authenticator:oauth2', identification, password).catch((error) => {
this.transitionToRoute('login');
this.set('loading', false);
this.get('flashMessages').error(error.error);
- }));
+ });
this.set('loading', false);
}
}
diff --git a/app/pods/login/route.js b/app/pods/login/route.js
index 457fe0c..c38d19e 100644
--- a/app/pods/login/route.js
+++ b/app/pods/login/route.js
@@ -1,4 +1,4 @@
import Ember from 'ember';
-import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';
+import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';
export default Ember.Route.extend(UnauthenticatedRouteMixin, {});
diff --git a/app/pods/protected/characteristics/edit/controller.js b/app/pods/protected/characteristics/edit/controller.js
index c16ce3f..2acb5dd 100644
--- a/app/pods/protected/characteristics/edit/controller.js
+++ b/app/pods/protected/characteristics/edit/controller.js
@@ -13,8 +13,9 @@ export default Ember.Controller.extend({
ajaxError(characteristic.get('errors'), this.get('flashMessages'));
});
} else {
- characteristic.deleteRecord();
- this.transitionToRoute('protected.characteristics.show', characteristic);
+ characteristic.deleteRecord().then(() => {
+ this.transitionToRoute('protected.characteristics.show', characteristic);
+ });
}
},
diff --git a/app/pods/protected/characteristics/edit/route.js b/app/pods/protected/characteristics/edit/route.js
index 1c04a5d..3f35133 100644
--- a/app/pods/protected/characteristics/edit/route.js
+++ b/app/pods/protected/characteristics/edit/route.js
@@ -1,10 +1,11 @@
import Ember from 'ember';
-import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
-export default Ember.Route.extend(AuthenticatedRouteMixin, {
+export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.characteristics.index');
}
diff --git a/app/pods/protected/characteristics/index/route.js b/app/pods/protected/characteristics/index/route.js
index 83aa3ef..3ee78f4 100644
--- a/app/pods/protected/characteristics/index/route.js
+++ b/app/pods/protected/characteristics/index/route.js
@@ -1,13 +1,17 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
model: function() {
return this.store.findAll('characteristic');
},
setupController: function(controller, model) {
controller.set('model', model);
- controller.set('metaData', this.store.metadataFor('characteristic'));
+ this.get('currentUser.account').then((user) => {
+ controller.set('metaData', user.get('metaData'));
+ });
},
});
diff --git a/app/pods/protected/characteristics/new/route.js b/app/pods/protected/characteristics/new/route.js
index 677a5fc..2773092 100644
--- a/app/pods/protected/characteristics/new/route.js
+++ b/app/pods/protected/characteristics/new/route.js
@@ -1,9 +1,11 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.characteristics.index');
}
diff --git a/app/pods/protected/characteristics/show/controller.js b/app/pods/protected/characteristics/show/controller.js
index 2ed7872..044b783 100644
--- a/app/pods/protected/characteristics/show/controller.js
+++ b/app/pods/protected/characteristics/show/controller.js
@@ -3,8 +3,9 @@ import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
delete: function() {
- this.get('model').destroyRecord();
- this.transitionToRoute('protected.characteristics.index');
+ this.get('model').destroyRecord().then(() => {
+ this.transitionToRoute('protected.characteristics.index');
+ });
},
},
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/route.js b/app/pods/protected/route.js
index acb1442..b1cdc95 100644
--- a/app/pods/protected/route.js
+++ b/app/pods/protected/route.js
@@ -1,5 +1,5 @@
import Ember from 'ember';
-import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
+import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
actions: {
diff --git a/app/pods/protected/species/edit/route.js b/app/pods/protected/species/edit/route.js
index e9e9076..1f5b616 100644
--- a/app/pods/protected/species/edit/route.js
+++ b/app/pods/protected/species/edit/route.js
@@ -1,9 +1,11 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.species.index');
}
@@ -18,7 +20,9 @@ export default Ember.Route.extend({
setupController: function(controller, model) {
controller.set('model', model);
- controller.set('metaData', this.store.metadataFor('species'));
+ this.get('currentUser.account').then((user) => {
+ controller.set('metaData', user.get('metaData'));
+ });
},
});
diff --git a/app/pods/protected/species/index/route.js b/app/pods/protected/species/index/route.js
index 755edff..89c832d 100644
--- a/app/pods/protected/species/index/route.js
+++ b/app/pods/protected/species/index/route.js
@@ -1,13 +1,17 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
model: function() {
return this.store.findAll('species');
},
setupController: function(controller, model) {
controller.set('model', model);
- controller.set('metaData', this.store.metadataFor('species'));
+ this.get('currentUser.account').then((user) => {
+ controller.set('metaData', user.get('metaData'));
+ });
},
});
diff --git a/app/pods/protected/species/new/controller.js b/app/pods/protected/species/new/controller.js
index 094ea14..1d2cecf 100644
--- a/app/pods/protected/species/new/controller.js
+++ b/app/pods/protected/species/new/controller.js
@@ -13,8 +13,9 @@ export default Ember.Controller.extend({
ajaxError(species.get('errors'), this.get('flashMessages'));
});
} else {
- species.deleteRecord();
- this.transitionToRoute('protected.species.index');
+ species.deleteRecord().then(() => {
+ this.transitionToRoute('protected.species.index');
+ });
}
},
diff --git a/app/pods/protected/species/new/route.js b/app/pods/protected/species/new/route.js
index 3f813d2..d265f9e 100644
--- a/app/pods/protected/species/new/route.js
+++ b/app/pods/protected/species/new/route.js
@@ -1,9 +1,11 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.species.index');
}
diff --git a/app/pods/protected/species/show/controller.js b/app/pods/protected/species/show/controller.js
index cadc1f4..b44b6a7 100644
--- a/app/pods/protected/species/show/controller.js
+++ b/app/pods/protected/species/show/controller.js
@@ -3,8 +3,9 @@ import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
delete: function() {
- this.get('model').destroyRecord();
- this.transitionToRoute('protected.species.index');
+ this.get('model').destroyRecord().then(() => {
+ this.transitionToRoute('protected.species.index');
+ });
},
},
diff --git a/app/pods/protected/strains/edit/controller.js b/app/pods/protected/strains/edit/controller.js
index b455768..ae093b7 100644
--- a/app/pods/protected/strains/edit/controller.js
+++ b/app/pods/protected/strains/edit/controller.js
@@ -13,8 +13,9 @@ export default Ember.Controller.extend({
ajaxError(strain.get('errors'), this.get('flashMessages'));
});
} else {
- strain.deleteRecord();
- this.transitionToRoute('protected.strains.show', strain);
+ strain.deleteRecord().then(() => {
+ this.transitionToRoute('protected.strains.show', strain);
+ });
}
},
diff --git a/app/pods/protected/strains/edit/route.js b/app/pods/protected/strains/edit/route.js
index 328d89d..ee75d51 100644
--- a/app/pods/protected/strains/edit/route.js
+++ b/app/pods/protected/strains/edit/route.js
@@ -1,10 +1,11 @@
import Ember from 'ember';
-import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
-export default Ember.Route.extend(AuthenticatedRouteMixin, {
+export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.strains.index');
}
@@ -26,7 +27,9 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
setupController: function(controller, models) {
controller.setProperties(models);
- controller.set('metaData', this.store.metadataFor('strain'));
+ this.get('currentUser.account').then((user) => {
+ controller.set('metaData', user.get('metaData'));
+ });
},
});
diff --git a/app/pods/protected/strains/index/route.js b/app/pods/protected/strains/index/route.js
index 14b7a5c..e5582d7 100644
--- a/app/pods/protected/strains/index/route.js
+++ b/app/pods/protected/strains/index/route.js
@@ -1,13 +1,17 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
model: function() {
return this.store.findAll('strain');
},
setupController: function(controller, model) {
controller.set('model', model);
- controller.set('metaData', this.store.metadataFor('strain'));
+ this.get('currentUser.account').then((user) => {
+ controller.set('metaData', user.get('metaData'));
+ });
},
});
diff --git a/app/pods/protected/strains/new/route.js b/app/pods/protected/strains/new/route.js
index 45ca831..6def196 100644
--- a/app/pods/protected/strains/new/route.js
+++ b/app/pods/protected/strains/new/route.js
@@ -1,9 +1,11 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.strains.index');
}
diff --git a/app/pods/protected/strains/show/controller.js b/app/pods/protected/strains/show/controller.js
index ab4d552..7128b9a 100644
--- a/app/pods/protected/strains/show/controller.js
+++ b/app/pods/protected/strains/show/controller.js
@@ -3,8 +3,9 @@ import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
delete: function() {
- this.get('model').destroyRecord();
- this.transitionToRoute('protected.strains.index');
+ this.get('model').destroyRecord().then(() => {
+ this.transitionToRoute('protected.strains.index');
+ });
},
},
diff --git a/app/pods/protected/strains/show/route.js b/app/pods/protected/strains/show/route.js
index 4c9634b..0a17d8b 100644
--- a/app/pods/protected/strains/show/route.js
+++ b/app/pods/protected/strains/show/route.js
@@ -1,7 +1,6 @@
import Ember from 'ember';
-import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
-export default Ember.Route.extend(AuthenticatedRouteMixin, {
+export default Ember.Route.extend({
model: function(params) {
return this.store.findRecord('strain', params.strain_id, { reload: true });
},
diff --git a/app/pods/protected/users/changepassword/controller.js b/app/pods/protected/users/changepassword/controller.js
index 94ce219..3b54073 100644
--- a/app/pods/protected/users/changepassword/controller.js
+++ b/app/pods/protected/users/changepassword/controller.js
@@ -2,6 +2,9 @@ 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,
actions: {
@@ -16,11 +19,11 @@ export default Ember.Controller.extend({
let options = {
method: 'POST',
data: {
- id: this.get('session.currentUser.id'),
+ id: this.get('currentUser.account.id'),
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/protected/users/changepassword/route.js b/app/pods/protected/users/changepassword/route.js
index 2e3f295..ce869dd 100644
--- a/app/pods/protected/users/changepassword/route.js
+++ b/app/pods/protected/users/changepassword/route.js
@@ -1,12 +1,14 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
let user_id = transition.params['protected.users.changepassword'].user_id;
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (user.get('id') !== user_id) {
this.transitionTo('protected.users.index');
}
diff --git a/app/pods/protected/users/edit/route.js b/app/pods/protected/users/edit/route.js
index 3a943b8..b95bdb2 100644
--- a/app/pods/protected/users/edit/route.js
+++ b/app/pods/protected/users/edit/route.js
@@ -1,12 +1,14 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
let user_id = transition.params['protected.users.edit'].user_id;
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (user.get('id') !== user_id && !user.get('isAdmin')) {
this.transitionTo('protected.users.index');
}
diff --git a/app/pods/protected/users/edit/template.hbs b/app/pods/protected/users/edit/template.hbs
index 2f2f678..e53c6e8 100644
--- a/app/pods/protected/users/edit/template.hbs
+++ b/app/pods/protected/users/edit/template.hbs
@@ -1,7 +1,7 @@
{{
protected/users/user-form
user=model
- currentUser=session.currentUser
+ currentUser=currentUser.account
save="save"
cancel="cancel"
}}
diff --git a/app/pods/protected/users/index/route.js b/app/pods/protected/users/index/route.js
index e8b6bc7..8429726 100644
--- a/app/pods/protected/users/index/route.js
+++ b/app/pods/protected/users/index/route.js
@@ -1,9 +1,11 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
- this.get('session.currentUser').then((user) => {
+ this.get('currentUser.account').then((user) => {
if (!user.get('isAdmin')) {
this.transitionTo('protected.index');
}
diff --git a/app/pods/protected/users/show/controller.js b/app/pods/protected/users/show/controller.js
index 481b126..3c6c549 100644
--- a/app/pods/protected/users/show/controller.js
+++ b/app/pods/protected/users/show/controller.js
@@ -1,7 +1,9 @@
import Ember from 'ember';
export default Ember.Controller.extend({
- isUser: Ember.computed('model.id', 'session.currentUser.id', function() {
- return this.get('model.id') === this.get('session.currentUser.id');
+ currentUser: Ember.inject.service('session-account'),
+
+ isUser: Ember.computed('model.id', 'currentUser.account.id', function() {
+ return this.get('model.id') === this.get('currentUser.account.id');
}),
});
diff --git a/app/pods/protected/users/show/route.js b/app/pods/protected/users/show/route.js
index 33eeba7..a0c9fd9 100644
--- a/app/pods/protected/users/show/route.js
+++ b/app/pods/protected/users/show/route.js
@@ -1,10 +1,12 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ currentUser: Ember.inject.service('session-account'),
+
beforeModel: function(transition) {
this._super(transition);
- this.get('session.currentUser').then((currentUser) => {
+ this.get('currentUser.account').then((currentUser) => {
let user_id = transition.params['protected.users.show'].user_id;
if (!currentUser.get('isAdmin') && currentUser.get('id') !== user_id) {
this.transitionTo('protected.users.index');
diff --git a/app/pods/users/index/route.js b/app/pods/users/index/route.js
deleted file mode 100644
index 2169a4f..0000000
--- a/app/pods/users/index/route.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import Ember from 'ember';
-import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
-
-export default Ember.Route.extend(AuthenticatedRouteMixin, {
- model: function() {
- return this.store.findAll('user');
- }
-});
diff --git a/app/pods/users/index/template.hbs b/app/pods/users/index/template.hbs
deleted file mode 100644
index f3239cb..0000000
--- a/app/pods/users/index/template.hbs
+++ /dev/null
@@ -1,3 +0,0 @@
-{{#each model as |user|}}
- {{user.email}}
-{{/each}}
diff --git a/app/pods/users/lockoutauthenticate/route.js b/app/pods/users/lockoutauthenticate/route.js
index f77c5dc..9924157 100644
--- a/app/pods/users/lockoutauthenticate/route.js
+++ b/app/pods/users/lockoutauthenticate/route.js
@@ -1,6 +1,8 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ session: Ember.inject.service('session'),
+
beforeModel: function(transition) {
this._super(transition);
diff --git a/app/pods/users/new/route.js b/app/pods/users/new/route.js
index 8d7010b..c3e757a 100644
--- a/app/pods/users/new/route.js
+++ b/app/pods/users/new/route.js
@@ -1,5 +1,5 @@
import Ember from 'ember';
-import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';
+import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';
export default Ember.Route.extend(UnauthenticatedRouteMixin, {
model: function() {
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/services/session-account.js b/app/services/session-account.js
new file mode 100644
index 0000000..1b34554
--- /dev/null
+++ b/app/services/session-account.js
@@ -0,0 +1,22 @@
+import Ember from 'ember';
+import DS from 'ember-data';
+import parseBase64 from '../utils/parse-base64';
+
+const { service } = Ember.inject;
+
+export default Ember.Service.extend({
+ session: service('session'),
+ store: service(),
+
+ account: Ember.computed('session.data.authenticated.access_token', function() {
+ const token = this.get('session.data.authenticated.access_token');
+ const claims = parseBase64(token);
+ const id = claims['sub'];
+
+ if (!Ember.isEmpty(id)) {
+ return DS.PromiseObject.create({
+ promise: this.get('store').findRecord('user', id),
+ });
+ }
+ })
+});
diff --git a/app/sessions/custom.js b/app/sessions/custom.js
deleted file mode 100644
index e5a8385..0000000
--- a/app/sessions/custom.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import Session from 'simple-auth/session';
-import parseBase64 from '../utils/parse-base64';
-
-export default Session.extend({
- currentUser: function() {
- let token = this.get('secure.token');
- if (token && this.get('isAuthenticated')) {
- let t = parseBase64(token);
- return this._store.findRecord('user', t['sub']);
- }
- }.property('secure.token', 'isAuthenticated')
-});
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);
};
diff --git a/bower.json b/bower.json
index 96af48e..e7a1dbd 100644
--- a/bower.json
+++ b/bower.json
@@ -13,7 +13,6 @@
"loader.js": "ember-cli/loader.js#3.2.1",
"qunit": "~1.18.0",
"flakes": "~1.0.0",
- "ember-simple-auth": "~0.8.0",
"moment": "~2.10.6",
"select2": "3.5.2",
"antiscroll": "git://github.com/azirbel/antiscroll.git#90391fb371c7be769bc32e7287c5271981428356",
diff --git a/config/environment.js b/config/environment.js
index 09c5283..a6f5a79 100644
--- a/config/environment.js
+++ b/config/environment.js
@@ -14,36 +14,14 @@ module.exports = function(environment) {
APP: {
genus: 'clostridium',
},
- podModulePrefix: 'clostridiumdotinfo/pods',
- 'simple-auth': {
- session: 'session:custom',
- authorizer: 'simple-auth-authorizer:token',
- store: 'simple-auth-session-store:local-storage',
- routeAfterAuthentication: 'protected.index',
- },
- 'simple-auth-token': {
- identificationField: 'email',
- passwordField: 'password',
- tokenPropertyName: 'token',
- authorizationPrefix: 'Bearer ',
- authorizationHeaderName: 'Authorization',
- refreshAccessTokens: true,
- timeFactor: 1000, // 1000 ms/s; JWT returned in unix time seconds
- refreshLeeway: 1800, // (60 s/min) * (30 min) = 1800 s
- },
- contentSecurityPolicy: {
- 'default-src': "'none'",
- 'script-src': "'self'",
- 'font-src': "'self'",
- 'img-src': "'self' data:",
- 'style-src': "'self' 'unsafe-inline'",
- 'media-src': "'self'"
- },
flashMessageDefaults: {
sticky: true,
type: 'error',
types: ['error', 'warning', 'success', 'information', 'tip', 'message'],
},
+ 'ember-simple-auth': {
+ routeAfterAuthentication: 'protected.compare',
+ },
};
var apiURL;
@@ -62,11 +40,7 @@ module.exports = function(environment) {
apiURL = 'https://bactdb.herokuapp.com';
}
- ENV['simple-auth']['crossOriginWhitelist'] = [apiURL];
- ENV['simple-auth-token']['serverTokenEndpoint'] = apiURL + '/api/authenticate';
- ENV['simple-auth-token']['serverTokenRefreshEndpoint'] = apiURL + '/api/refresh';
ENV.apiURL = apiURL;
- ENV.contentSecurityPolicy['connect-src'] = "'self' " + apiURL;
return ENV;
};
diff --git a/package.json b/package.json
index 46f732c..6a08cf6 100644
--- a/package.json
+++ b/package.json
@@ -23,7 +23,6 @@
"ember-cli": "1.13.8",
"ember-cli-app-version": "0.5.0",
"ember-cli-babel": "^5.1.3",
- "ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.0.1",
"ember-cli-divshot": "^0.1.7",
"ember-cli-flash": "1.3.3",
@@ -32,8 +31,7 @@
"ember-cli-ic-ajax": "0.2.1",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-qunit": "^1.0.0",
- "ember-cli-simple-auth": "^0.8.0",
- "ember-cli-simple-auth-token": "^0.7.2",
+ "ember-simple-auth": "1.0.0",
"ember-cli-release": "0.2.3",
"ember-cli-sri": "^1.0.3",
"ember-cli-uglify": "^1.2.0",