summaryrefslogtreecommitdiff
path: root/client/js/services/Identity.js
blob: 702100318c385ccafd7e28197b0d1d249c9bac22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

mainApp.factory('Identity',[ '$http', function($http){

	/* Create profile structure */
    var profile={};
    profile.username="Undefined";
    profile.projectname="Undefined";
	profile.token="";

	
	/**
	 * 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;
		
		return $http.post('../server/index.php',
						  $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));  
	};


	/**
	 * 
	 * @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;
	};



	// Return services objects
	return {
		login: login,
		parseLoginAnswer: parseLoginAnswer,
		profile: profile	
	};

	
}]);