2015-01-30 12:21:18 +10:30
|
|
|
import Base from 'simple-auth/authenticators/base';
|
|
|
|
import config from '../config/environment';
|
|
|
|
|
|
|
|
export default Base.extend({
|
|
|
|
|
|
|
|
authenticate: function(credentials) {
|
|
|
|
var container = this.container;
|
|
|
|
return new Ember.RSVP.Promise(function(resolve, reject) {
|
|
|
|
Ember.$.ajax({
|
2015-02-24 20:33:18 +10:30
|
|
|
url: config.baseURL+'login',
|
2015-01-30 12:21:18 +10:30
|
|
|
type: 'POST',
|
|
|
|
data: { identification: credentials.identification, password: credentials.password }
|
|
|
|
}).then(function(response) {
|
2015-02-24 20:33:18 +10:30
|
|
|
container.lookup('store:main').find('user', response.userId).then(function(user) {
|
|
|
|
resolve({ token: response.token, userId: response.userId, user: user });
|
|
|
|
});
|
2015-01-30 12:21:18 +10:30
|
|
|
}, function(xhr, status, error) {
|
2015-02-24 20:33:18 +10:30
|
|
|
reject(xhr.responseJSON.errors);
|
2015-01-30 12:21:18 +10:30
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-02-24 20:33:18 +10:30
|
|
|
invalidate: function(data) {
|
|
|
|
return new Ember.RSVP.Promise(function() {
|
|
|
|
window.location = config.baseURL+'logout';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|