mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-23 00:00:02 +01:00
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
/**
|
|
* File: custom.js
|
|
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
|
|
* Date: 26.06.2016
|
|
* Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC
|
|
* This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential.
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
|
**********************************************************************************/
|
|
|
|
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();
|
|
}
|
|
});
|