64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
|
|
mainApp.factory('Identity',[ '$http', function($http){
|
|
|
|
/* Create profile structure */
|
|
var profile={};
|
|
profile.username="Undefined";
|
|
profile.projectname="Undefined";
|
|
profile.token="";
|
|
|
|
/* Will contain the result of the $http request */
|
|
var $httpResponse;
|
|
|
|
/**
|
|
* Function to connect to OpenStack
|
|
*
|
|
* @param {object} $http Angular $http service
|
|
* @param {string} username The user name
|
|
* @param {string} password The user password
|
|
* @param {string} projectname The user project name
|
|
* @returns {promise} The result of the request
|
|
*/
|
|
var login=function(username, password,projectname){
|
|
profile.username=username;
|
|
profile.projectname=projectname;
|
|
|
|
$httpResponse=$http.post('../server/index.php',
|
|
$.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
|
|
return $httpResponse;
|
|
};
|
|
|
|
|
|
/**
|
|
*
|
|
* @param {string} response The response to parse
|
|
* @returns {requestParserResult} Formated data
|
|
*/
|
|
var parseLoginAnswer=function(response){
|
|
var requestParserResult={};
|
|
|
|
requestParserResult.status=0;
|
|
requestParserResult.data=response.data;
|
|
profile.token="Un Token";
|
|
|
|
// TODO
|
|
|
|
|
|
return requestParserResult;
|
|
};
|
|
|
|
|
|
var getResponse=function(){
|
|
return parseLoginAnswer($httpResponse);
|
|
}
|
|
|
|
|
|
// Return services objects
|
|
return {
|
|
login: login,
|
|
getResponse: getResponse,
|
|
profile: profile
|
|
};
|
|
|
|
|
|
}]);
|