merge
This commit is contained in:
parent
6349739a6c
commit
cfce59d6dc
47 changed files with 500 additions and 52 deletions
|
@ -2,11 +2,12 @@
|
|||
mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
|
||||
|
||||
|
||||
|
||||
// Create data
|
||||
var data={};
|
||||
data.machines={};
|
||||
|
||||
|
||||
|
||||
// Parser
|
||||
var parseGetMachinesAnswer=function(response, failedToSendRequest){
|
||||
|
||||
|
@ -16,8 +17,24 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
|
|||
// Get Machine
|
||||
var getMachines=function(callback){
|
||||
|
||||
var params={
|
||||
"token" : Identity.getToken(),
|
||||
"task" : "compute",
|
||||
"action":"getServer",
|
||||
"serverId":"69d5bcc4-2fab-4634-b0d2-f455fee5b7bd"
|
||||
};
|
||||
|
||||
var result=$http.post('../server/index.php',
|
||||
$.param({"token" : Identity.profile.token, "task" : "Compute"}));
|
||||
$.param(params));
|
||||
|
||||
// Wait and handle the response
|
||||
result.then(function (response){
|
||||
console.log(response.data.Servers);
|
||||
callback(parseGetMachinesAnswer(response, false));
|
||||
},function(response){
|
||||
alert(response.status);
|
||||
callback(parseGetMachinesAnswer(response, true));
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
@ -31,8 +48,8 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
|
|||
|
||||
// Return services objects
|
||||
return {
|
||||
getMachines: getMachines
|
||||
pullData: pullData
|
||||
getMachines: getMachines,
|
||||
pullData: pullData,
|
||||
data:data
|
||||
};
|
||||
|
||||
|
|
|
@ -7,37 +7,47 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
|||
var profile={};
|
||||
profile.username=null;
|
||||
profile.projectname=null;
|
||||
profile.token=null;
|
||||
|
||||
|
||||
/**
|
||||
* Save profile in cookies
|
||||
*/
|
||||
var saveCookieForSession=function(){
|
||||
$cookies.putObject('profile', 5);
|
||||
};
|
||||
|
||||
var token=null;
|
||||
|
||||
|
||||
/*
|
||||
* @returns {boolean} Return true if a cookie is found (and load it in profile) false else
|
||||
*/
|
||||
var isAlreadyLogin=function(){
|
||||
|
||||
// Load cookies
|
||||
var profileInCookie=$cookies.getObject('profile');
|
||||
console.log(profileInCookie);
|
||||
var tokenPart_0InCookie=$cookies.getObject('token.part_0');
|
||||
var tokenPart_1InCookie=$cookies.getObject('token.part_1');
|
||||
|
||||
|
||||
if(typeof profileInCookie !== 'undefined'){
|
||||
// Check if cookie is defined
|
||||
if(typeof profileInCookie !== 'undefined'
|
||||
&& typeof tokenPart_0InCookie !== 'undefined'
|
||||
&& typeof tokenPart_1InCookie !== 'undefined'
|
||||
){
|
||||
|
||||
// If yes, put it into variables
|
||||
angular.extend(profile, profileInCookie);
|
||||
token=tokenPart_0InCookie+tokenPart_1InCookie;
|
||||
|
||||
// Return I'm Login
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return I'm not Login
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Destroy profile cookies
|
||||
*/
|
||||
var logout=function(){
|
||||
$cookies.remove('profile');
|
||||
$cookies.remove('token.part_0');
|
||||
$cookies.remove('token.part_1');
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,15 +59,28 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
|||
*/
|
||||
var parseLoginAnswer=function(response, failedToSendRequest){
|
||||
|
||||
|
||||
// Defined return object
|
||||
var requestParserResult={};
|
||||
requestParserResult.status=1;
|
||||
requestParserResult.failReason=null;
|
||||
|
||||
if (typeof response.data.token !== 'undefined') {
|
||||
// Set status code
|
||||
requestParserResult.status=0;
|
||||
profile.token=response.data.token;
|
||||
saveCookieForSession();
|
||||
|
||||
// Find the middle of the token to split it
|
||||
var middle=parseInt(response.data.token.length/2);
|
||||
|
||||
// Create expire date (cookie expire in 55 mins)
|
||||
var expireDate=new Date();
|
||||
expireDate.setMinutes(expireDate.getMinutes()+55);
|
||||
|
||||
// Save profile
|
||||
$cookies.putObject('profile', profile, {'expires': expireDate});
|
||||
// Save first part of token
|
||||
$cookies.putObject('token.part_0', response.data.token.substring(0, middle), {'expires': expireDate});
|
||||
// Save second part of token
|
||||
$cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length), {'expires': expireDate});
|
||||
}
|
||||
else if(failedToSendRequest){
|
||||
requestParserResult.failReason="Failed to send request";
|
||||
|
@ -69,7 +92,6 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
|||
return requestParserResult;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function to connect to OpenStack
|
||||
|
@ -87,24 +109,39 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
|||
profile.projectname=projectname;
|
||||
|
||||
var result=$http.post('../server/index.php',
|
||||
$.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
|
||||
$.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
|
||||
|
||||
// Wait and handle the response
|
||||
result.then(function (response){
|
||||
callback(parseLoginAnswer(response), false);
|
||||
callback(parseLoginAnswer(response, false));
|
||||
},function(response){
|
||||
callback(parseLoginAnswer(response), true)
|
||||
callback(parseLoginAnswer(response, true));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Get the profile
|
||||
*/
|
||||
var getProfile=function(){
|
||||
return profile;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the token
|
||||
*/
|
||||
var getToken=function(){
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
// Return services objects
|
||||
return {
|
||||
login: login,
|
||||
profile: profile,
|
||||
getProfile: getProfile,
|
||||
isAlreadyLogin: isAlreadyLogin,
|
||||
logout:logout
|
||||
logout:logout,
|
||||
getToken:getToken
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue