Swapped custom auth for component.
This commit is contained in:
parent
8dbd01c7b1
commit
8e37bce7c7
8 changed files with 33 additions and 82 deletions
|
@ -1,48 +0,0 @@
|
|||
import Ember from 'ember';
|
||||
import Base from 'simple-auth/authenticators/base';
|
||||
import config from '../config/environment';
|
||||
|
||||
export default Base.extend({
|
||||
tokenEndpoint: config.apiURL + '/api/authenticate',
|
||||
|
||||
restore: function(data) {
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
if (!Ember.isEmpty(data.token)) {
|
||||
resolve(data);
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
authenticate: function(credentials) {
|
||||
var _this = this;
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
Ember.$.ajax({
|
||||
url: _this.tokenEndpoint,
|
||||
type: 'POST',
|
||||
data: {username: credentials.identification, password: credentials.password},
|
||||
contentType: 'application/x-www-form-urlencoded'
|
||||
}).then(function(response) {
|
||||
Ember.run(function() {
|
||||
resolve({ token: response.token });
|
||||
});
|
||||
}, function(xhr) {
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
Ember.run(function() {
|
||||
reject(response.error);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
invalidate: function() {
|
||||
var _this = this;
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
Ember.$.ajax({ url: _this.tokenEndpoint, type: 'DELETE' }).always(function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
});
|
|
@ -1,10 +0,0 @@
|
|||
import Ember from 'ember';
|
||||
import Base from 'simple-auth/authorizers/base';
|
||||
|
||||
export default Base.extend({
|
||||
authorize: function(jqXHR) {
|
||||
if (this.get('session.isAuthenticated') && !Ember.isEmpty(this.get('session.token'))) {
|
||||
jqXHR.setRequestHeader('Authorization', 'Bearer ' + this.get('session.token'));
|
||||
}
|
||||
}
|
||||
});
|
|
@ -2,13 +2,5 @@ import Ember from 'ember';
|
|||
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
|
||||
|
||||
export default Ember.Controller.extend(LoginControllerMixin, {
|
||||
authenticator: 'authenticators:custom',
|
||||
actions: {
|
||||
authenticate: function() {
|
||||
var _this = this;
|
||||
this._super().then(null, function(message) {
|
||||
_this.set('errorMessage', message);
|
||||
});
|
||||
}
|
||||
}
|
||||
authenticator: 'simple-auth-authenticator:jwt'
|
||||
});
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import Authenticator from './../authenticators/custom';
|
||||
import Authorizer from './../authorizers/custom';
|
||||
|
||||
export default {
|
||||
name: 'bling',
|
||||
initialize: function(container) {
|
||||
container.register('authenticators:custom', Authenticator);
|
||||
container.register('authorizers:custom', Authorizer);
|
||||
}
|
||||
};
|
Reference in a new issue