Merge pull request #35 from thermokarst/esa10
ember-simple-auth 1.0 Fixes #29.
This commit is contained in:
commit
ddc2eb725c
46 changed files with 143 additions and 119 deletions
6
app/authenticators/oauth2.js
Normal file
6
app/authenticators/oauth2.js
Normal file
|
@ -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`,
|
||||||
|
});
|
3
app/authorizers/application.js
Normal file
3
app/authorizers/application.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer';
|
||||||
|
|
||||||
|
export default OAuth2Bearer.extend({});
|
|
@ -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
|
|
||||||
};
|
|
|
@ -1,6 +1,9 @@
|
||||||
import DS from 'ember-data';
|
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() {
|
namespace: function() {
|
||||||
return 'api/' + this.get('globals.genus');
|
return 'api/' + this.get('globals.genus');
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Ember from 'ember';
|
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, {
|
export default Ember.Route.extend(ApplicationRouteMixin, {
|
||||||
actions: {
|
actions: {
|
||||||
|
|
|
@ -3,6 +3,9 @@ import Ember from 'ember';
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: ["flakes-frame"],
|
classNames: ["flakes-frame"],
|
||||||
|
|
||||||
|
session: Ember.inject.service('session'),
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
FlakesFrame.init();
|
FlakesFrame.init();
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
{{#link-to 'protected.characteristics' tagName='li' href=false}}
|
{{#link-to 'protected.characteristics' tagName='li' href=false}}
|
||||||
{{link-to 'Characteristics' 'protected.characteristics'}}
|
{{link-to 'Characteristics' 'protected.characteristics'}}
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
{{#if session.currentUser.isAdmin}}
|
{{#if currentUser.account.isAdmin}}
|
||||||
{{#link-to 'protected.users' tagName='li' href=false}}
|
{{#link-to 'protected.users' tagName='li' href=false}}
|
||||||
{{link-to 'Users' 'protected.users'}}
|
{{link-to 'Users' 'protected.users'}}
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
</ul>
|
</ul>
|
||||||
<p class="foot">
|
<p class="foot">
|
||||||
{{link-to session.currentUser.name 'protected.users.show' session.currentUser.id}}<br>
|
{{link-to currentUser.account.name 'protected.users.show' currentUser.account.id}}<br>
|
||||||
<a {{action 'invalidateSession'}}>Logout</a>
|
<a {{action 'invalidateSession'}}>Logout</a>
|
||||||
</p>
|
</p>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
session: Ember.inject.service('session'),
|
||||||
|
|
||||||
loading: false,
|
loading: false,
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
authenticate: function() {
|
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
|
// Manually clean up because there might not be a transition
|
||||||
this.get('flashMessages').clearMessages();
|
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.transitionToRoute('login');
|
||||||
this.set('loading', false);
|
this.set('loading', false);
|
||||||
this.get('flashMessages').error(error.error);
|
this.get('flashMessages').error(error.error);
|
||||||
}));
|
});
|
||||||
this.set('loading', false);
|
this.set('loading', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import Ember from 'ember';
|
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, {});
|
export default Ember.Route.extend(UnauthenticatedRouteMixin, {});
|
||||||
|
|
|
@ -13,8 +13,9 @@ export default Ember.Controller.extend({
|
||||||
ajaxError(characteristic.get('errors'), this.get('flashMessages'));
|
ajaxError(characteristic.get('errors'), this.get('flashMessages'));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
characteristic.deleteRecord();
|
characteristic.deleteRecord().then(() => {
|
||||||
this.transitionToRoute('protected.characteristics.show', characteristic);
|
this.transitionToRoute('protected.characteristics.show', characteristic);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import Ember from 'ember';
|
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) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
if (user.get('isReader')) {
|
if (user.get('isReader')) {
|
||||||
this.transitionTo('protected.characteristics.index');
|
this.transitionTo('protected.characteristics.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
model: function() {
|
model: function() {
|
||||||
return this.store.findAll('characteristic');
|
return this.store.findAll('characteristic');
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
controller.set('model', model);
|
controller.set('model', model);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
controller.set('metaData', user.get('metaData'));
|
controller.set('metaData', user.get('metaData'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
if (user.get('isReader')) {
|
if (user.get('isReader')) {
|
||||||
this.transitionTo('protected.characteristics.index');
|
this.transitionTo('protected.characteristics.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ import Ember from 'ember';
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
actions: {
|
actions: {
|
||||||
delete: function() {
|
delete: function() {
|
||||||
this.get('model').destroyRecord();
|
this.get('model').destroyRecord().then(() => {
|
||||||
this.transitionToRoute('protected.characteristics.index');
|
this.transitionToRoute('protected.characteristics.index');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Ember from 'ember';
|
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, {
|
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||||
actions: {
|
actions: {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
if (user.get('isReader')) {
|
if (user.get('isReader')) {
|
||||||
this.transitionTo('protected.species.index');
|
this.transitionTo('protected.species.index');
|
||||||
}
|
}
|
||||||
|
@ -18,7 +20,7 @@ export default Ember.Route.extend({
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
controller.set('model', model);
|
controller.set('model', model);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
controller.set('metaData', user.get('metaData'));
|
controller.set('metaData', user.get('metaData'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
model: function() {
|
model: function() {
|
||||||
return this.store.findAll('species');
|
return this.store.findAll('species');
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
controller.set('model', model);
|
controller.set('model', model);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
controller.set('metaData', user.get('metaData'));
|
controller.set('metaData', user.get('metaData'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,8 +13,9 @@ export default Ember.Controller.extend({
|
||||||
ajaxError(species.get('errors'), this.get('flashMessages'));
|
ajaxError(species.get('errors'), this.get('flashMessages'));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
species.deleteRecord();
|
species.deleteRecord().then(() => {
|
||||||
this.transitionToRoute('protected.species.index');
|
this.transitionToRoute('protected.species.index');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
if (user.get('isReader')) {
|
if (user.get('isReader')) {
|
||||||
this.transitionTo('protected.species.index');
|
this.transitionTo('protected.species.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ import Ember from 'ember';
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
actions: {
|
actions: {
|
||||||
delete: function() {
|
delete: function() {
|
||||||
this.get('model').destroyRecord();
|
this.get('model').destroyRecord().then(() => {
|
||||||
this.transitionToRoute('protected.species.index');
|
this.transitionToRoute('protected.species.index');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,9 @@ export default Ember.Controller.extend({
|
||||||
ajaxError(strain.get('errors'), this.get('flashMessages'));
|
ajaxError(strain.get('errors'), this.get('flashMessages'));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
strain.deleteRecord();
|
strain.deleteRecord().then(() => {
|
||||||
this.transitionToRoute('protected.strains.show', strain);
|
this.transitionToRoute('protected.strains.show', strain);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import Ember from 'ember';
|
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) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
if (user.get('isReader')) {
|
if (user.get('isReader')) {
|
||||||
this.transitionTo('protected.strains.index');
|
this.transitionTo('protected.strains.index');
|
||||||
}
|
}
|
||||||
|
@ -26,7 +27,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||||
|
|
||||||
setupController: function(controller, models) {
|
setupController: function(controller, models) {
|
||||||
controller.setProperties(models);
|
controller.setProperties(models);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
controller.set('metaData', user.get('metaData'));
|
controller.set('metaData', user.get('metaData'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
model: function() {
|
model: function() {
|
||||||
return this.store.findAll('strain');
|
return this.store.findAll('strain');
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
controller.set('model', model);
|
controller.set('model', model);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
controller.set('metaData', user.get('metaData'));
|
controller.set('metaData', user.get('metaData'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
if (user.get('isReader')) {
|
if (user.get('isReader')) {
|
||||||
this.transitionTo('protected.strains.index');
|
this.transitionTo('protected.strains.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ import Ember from 'ember';
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
actions: {
|
actions: {
|
||||||
delete: function() {
|
delete: function() {
|
||||||
this.get('model').destroyRecord();
|
this.get('model').destroyRecord().then(() => {
|
||||||
this.transitionToRoute('protected.strains.index');
|
this.transitionToRoute('protected.strains.index');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import Ember from 'ember';
|
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) {
|
model: function(params) {
|
||||||
return this.store.findRecord('strain', params.strain_id, { reload: true });
|
return this.store.findRecord('strain', params.strain_id, { reload: true });
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,9 @@ 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'),
|
||||||
|
|
||||||
passwordConfirm: null,
|
passwordConfirm: null,
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -16,11 +19,11 @@ export default Ember.Controller.extend({
|
||||||
let options = {
|
let options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
id: this.get('session.currentUser.id'),
|
id: this.get('currentUser.account.id'),
|
||||||
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.');
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
|
|
||||||
let user_id = transition.params['protected.users.changepassword'].user_id;
|
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) {
|
if (user.get('id') !== user_id) {
|
||||||
this.transitionTo('protected.users.index');
|
this.transitionTo('protected.users.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
|
|
||||||
let user_id = transition.params['protected.users.edit'].user_id;
|
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')) {
|
if (user.get('id') !== user_id && !user.get('isAdmin')) {
|
||||||
this.transitionTo('protected.users.index');
|
this.transitionTo('protected.users.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{{
|
{{
|
||||||
protected/users/user-form
|
protected/users/user-form
|
||||||
user=model
|
user=model
|
||||||
currentUser=session.currentUser
|
currentUser=currentUser.account
|
||||||
save="save"
|
save="save"
|
||||||
cancel="cancel"
|
cancel="cancel"
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
this.get('session.currentUser').then((user) => {
|
this.get('currentUser.account').then((user) => {
|
||||||
if (!user.get('isAdmin')) {
|
if (!user.get('isAdmin')) {
|
||||||
this.transitionTo('protected.index');
|
this.transitionTo('protected.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
isUser: Ember.computed('model.id', 'session.currentUser.id', function() {
|
currentUser: Ember.inject.service('session-account'),
|
||||||
return this.get('model.id') === this.get('session.currentUser.id');
|
|
||||||
|
isUser: Ember.computed('model.id', 'currentUser.account.id', function() {
|
||||||
|
return this.get('model.id') === this.get('currentUser.account.id');
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
currentUser: Ember.inject.service('session-account'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(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;
|
let user_id = transition.params['protected.users.show'].user_id;
|
||||||
if (!currentUser.get('isAdmin') && currentUser.get('id') !== user_id) {
|
if (!currentUser.get('isAdmin') && currentUser.get('id') !== user_id) {
|
||||||
this.transitionTo('protected.users.index');
|
this.transitionTo('protected.users.index');
|
||||||
|
|
|
@ -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');
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -1,3 +0,0 @@
|
||||||
{{#each model as |user|}}
|
|
||||||
{{user.email}}<br>
|
|
||||||
{{/each}}
|
|
|
@ -1,6 +1,8 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
|
session: Ember.inject.service('session'),
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
this._super(transition);
|
this._super(transition);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Ember from 'ember';
|
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, {
|
export default Ember.Route.extend(UnauthenticatedRouteMixin, {
|
||||||
model: function() {
|
model: function() {
|
||||||
|
|
|
@ -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');
|
||||||
},
|
},
|
||||||
|
|
22
app/services/session-account.js
Normal file
22
app/services/session-account.js
Normal file
|
@ -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),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
|
@ -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')
|
|
||||||
});
|
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
"loader.js": "ember-cli/loader.js#3.2.1",
|
"loader.js": "ember-cli/loader.js#3.2.1",
|
||||||
"qunit": "~1.18.0",
|
"qunit": "~1.18.0",
|
||||||
"flakes": "~1.0.0",
|
"flakes": "~1.0.0",
|
||||||
"ember-simple-auth": "~0.8.0",
|
|
||||||
"moment": "~2.10.6",
|
"moment": "~2.10.6",
|
||||||
"select2": "3.5.2",
|
"select2": "3.5.2",
|
||||||
"antiscroll": "git://github.com/azirbel/antiscroll.git#90391fb371c7be769bc32e7287c5271981428356",
|
"antiscroll": "git://github.com/azirbel/antiscroll.git#90391fb371c7be769bc32e7287c5271981428356",
|
||||||
|
|
|
@ -15,35 +15,14 @@ module.exports = function(environment) {
|
||||||
genus: 'hymenobacter',
|
genus: 'hymenobacter',
|
||||||
},
|
},
|
||||||
podModulePrefix: 'hymenobacterdotinfo/pods',
|
podModulePrefix: 'hymenobacterdotinfo/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: {
|
flashMessageDefaults: {
|
||||||
sticky: true,
|
sticky: true,
|
||||||
type: 'error',
|
type: 'error',
|
||||||
types: ['error', 'warning', 'success', 'information', 'tip', 'message'],
|
types: ['error', 'warning', 'success', 'information', 'tip', 'message'],
|
||||||
},
|
},
|
||||||
|
'ember-simple-auth': {
|
||||||
|
routeAfterAuthentication: 'protected.compare',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var apiURL;
|
var apiURL;
|
||||||
|
@ -62,11 +41,7 @@ module.exports = function(environment) {
|
||||||
apiURL = 'https://bactdb.herokuapp.com';
|
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.apiURL = apiURL;
|
||||||
ENV.contentSecurityPolicy['connect-src'] = "'self' " + apiURL;
|
|
||||||
|
|
||||||
return ENV;
|
return ENV;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
"ember-cli": "1.13.8",
|
"ember-cli": "1.13.8",
|
||||||
"ember-cli-app-version": "0.5.0",
|
"ember-cli-app-version": "0.5.0",
|
||||||
"ember-cli-babel": "^5.1.3",
|
"ember-cli-babel": "^5.1.3",
|
||||||
"ember-cli-content-security-policy": "0.4.0",
|
|
||||||
"ember-cli-dependency-checker": "^1.0.1",
|
"ember-cli-dependency-checker": "^1.0.1",
|
||||||
"ember-cli-divshot": "^0.1.7",
|
"ember-cli-divshot": "^0.1.7",
|
||||||
"ember-cli-flash": "1.3.3",
|
"ember-cli-flash": "1.3.3",
|
||||||
|
@ -32,8 +31,7 @@
|
||||||
"ember-cli-ic-ajax": "0.2.1",
|
"ember-cli-ic-ajax": "0.2.1",
|
||||||
"ember-cli-inject-live-reload": "^1.3.1",
|
"ember-cli-inject-live-reload": "^1.3.1",
|
||||||
"ember-cli-qunit": "^1.0.0",
|
"ember-cli-qunit": "^1.0.0",
|
||||||
"ember-cli-simple-auth": "^0.8.0",
|
"ember-simple-auth": "1.0.0",
|
||||||
"ember-cli-simple-auth-token": "^0.7.2",
|
|
||||||
"ember-cli-release": "0.2.3",
|
"ember-cli-release": "0.2.3",
|
||||||
"ember-cli-sri": "^1.0.3",
|
"ember-cli-sri": "^1.0.3",
|
||||||
"ember-cli-uglify": "^1.2.0",
|
"ember-cli-uglify": "^1.2.0",
|
||||||
|
|
Reference in a new issue