1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-23 00:00:02 +01:00
VILLASweb/app/authenticators/custom.js
Markus Grigull 15d29d23b2 Add jQuery UI
Add resizeable, droppable and draggable mixins
Add API_HOST in environment.js
2016-07-15 12:09:31 +02:00

48 lines
1.2 KiB
JavaScript

import Ember from 'ember';
import Base from 'ember-simple-auth/authenticators/base';
import ENV from '../config/environment';
export default Base.extend({
tokenEndpoint: 'http://' + ENV.APP.API_HOST + '/api/v1/authenticate',
restore(data) {
return new Ember.RSVP.Promise(function(resolve, reject) {
if (!Ember.isEmpty(data.token)) {
resolve(data);
} else {
reject();
}
});
},
authenticate(username, password) {
return new Ember.RSVP.Promise((resolve, reject) => {
Ember.$.ajax({
url: this.tokenEndpoint,
type: 'POST',
data: JSON.stringify({
username: username,
password: password
}),
contentType: 'application/json',
dataType: 'json'
}).then(function(response) {
Ember.run(function() {
resolve({
token: response.token
});
});
}, function(xhr) {
var response = JSON.parse(xhr.responseText);
Ember.run(function() {
reject(response.message);
});
});
});
},
invalidate() {
console.log('invalidate...');
return Ember.RSVP.resolve();
}
});