Login Service complete !
This commit is contained in:
parent
0c98543594
commit
3f83cae417
6 changed files with 94 additions and 61 deletions
|
@ -1,14 +1,42 @@
|
|||
|
||||
mainApp.factory('Identity',[ '$http', function($http){
|
||||
|
||||
/* Create profile structure */
|
||||
/* Create profile structure to store informations
|
||||
* about current session
|
||||
*/
|
||||
var profile={};
|
||||
profile.username="Undefined";
|
||||
profile.projectname="Undefined";
|
||||
profile.token="";
|
||||
profile.username=null;
|
||||
profile.projectname=null;
|
||||
profile.token=null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} response The response to parse
|
||||
* @param {boolean} to check if the request is send or not
|
||||
* @returns {requestParserResult} Formated data
|
||||
*/
|
||||
var parseLoginAnswer=function(response, failedToSendRequest){
|
||||
|
||||
var requestParserResult={};
|
||||
requestParserResult.status=1;
|
||||
requestParserResult.failReason=null;
|
||||
|
||||
if (typeof response.data.token !== 'undefined') {
|
||||
requestParserResult.status=0;
|
||||
profile.token=response.data.token;
|
||||
}
|
||||
else if(failedToSendRequest){
|
||||
requestParserResult.failReason="Failed to send request";
|
||||
}
|
||||
else{
|
||||
requestParserResult.failReason="Please check your username, password and project name !";
|
||||
}
|
||||
|
||||
return requestParserResult;
|
||||
};
|
||||
|
||||
|
||||
/* Will contain the result of the $http request */
|
||||
var $httpResponse;
|
||||
|
||||
/**
|
||||
* Function to connect to OpenStack
|
||||
|
@ -17,46 +45,28 @@ mainApp.factory('Identity',[ '$http', function($http){
|
|||
* @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
|
||||
* @param {function} function to call when data is avalaible
|
||||
*/
|
||||
var login=function(username, password,projectname){
|
||||
var login=function(username, password,projectname, callback){
|
||||
|
||||
// Set profile information (early)
|
||||
profile.username=username;
|
||||
profile.projectname=projectname;
|
||||
|
||||
$httpResponse=$http.post('../server/index.php',
|
||||
var result=$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);
|
||||
}
|
||||
|
||||
// Wait and handle the response
|
||||
result.then(function (response){
|
||||
callback(parseLoginAnswer(response), false);
|
||||
},function(response){
|
||||
callback(parseLoginAnswer(response), true)
|
||||
});
|
||||
};
|
||||
|
||||
// Return services objects
|
||||
return {
|
||||
login: login,
|
||||
getResponse: getResponse,
|
||||
profile: profile
|
||||
};
|
||||
|
||||
|
|
25
client/js/services/Image.js
Normal file
25
client/js/services/Image.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
|
||||
|
||||
var httpResponse;
|
||||
|
||||
var uploadImage=function(image){
|
||||
|
||||
};
|
||||
|
||||
var parseUploadImageRequest=function(){
|
||||
|
||||
};
|
||||
|
||||
var getResponse=function(){
|
||||
return parseUploadImageRequest(httpResponse);
|
||||
};
|
||||
|
||||
// Return services objects
|
||||
return {
|
||||
uploadImage: uploadImage,
|
||||
getResponse: getResponse
|
||||
};
|
||||
|
||||
|
||||
}]);
|
Loading…
Add table
Add a link
Reference in a new issue