diff --git a/client/index.html b/client/index.html index 10eceb3..ab5f00f 100644 --- a/client/index.html +++ b/client/index.html @@ -73,6 +73,7 @@ + diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 60eb52f..6358a6d 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -4,7 +4,7 @@ * @param {$scope} $scope The $scope angular service * @param {$sce} $sce The $sce angular service * @param {$http} $http The $http angular service - * @param {sharedProfile} sharedProfile The sharedProfile service + * @param {Identity} The Identity service */ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity) @@ -16,42 +16,39 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s $('#loginButton').click(function(){ + + // Begin login state for template $('#loginButton').hide(); $('#loadingLoginButton').show(); $('#failedToLoginAlert').hide(); + // Get data from templates var username=$("#loginFormUsername").val(); var password=$("#loginFormPassword").val(); var projectname=$("#loginFormProjectname").val(); - var result=Identity.login(username, password, projectname); - - - result.then(function (response){ - // Parser result - var response=Identity.getResponse(); - - // Check for error + // Function to call to handle result + var responseCallback=function(response){ + if(response.status!==0){ - + // Set reason of fail + $scope.failReason=response.failReason; + + // Display the error $('#failedToLoginAlert').show(); } else { + // Else the user is online ! $('#loginModal').modal('hide'); } // Reset button state $('#loginButton').show(); - $('#loadingLoginButton').hide(); - },function(response){ - $('#failedToLoginAlert').show(); - - // Reset button state - $('#loginButton').show(); - $('#loadingLoginButton').hide(); - }); - - - - }); + $('#loadingLoginButton').hide(); + } + + // Try to login + Identity.login(username, password, projectname, responseCallback); + }); + }]); diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index 7425244..2930e34 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -4,7 +4,7 @@ * The status controller * * @param {$scope} $scope The $scope service from angular - * @param {sharedProfile} sharedProfile The sharedProfile build by ourself + * @param {Identity} The Identity service */ mainApp.controller('statusCtrl', ['$scope','Identity', function ($scope, Identity) { diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 509f800..4c8919c 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -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 }; diff --git a/client/js/services/Image.js b/client/js/services/Image.js new file mode 100644 index 0000000..4cb3590 --- /dev/null +++ b/client/js/services/Image.js @@ -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 + }; + + +}]); diff --git a/client/partials/login.html b/client/partials/login.html index e0ce876..cd7d9ec 100644 --- a/client/partials/login.html +++ b/client/partials/login.html @@ -33,9 +33,9 @@
- \ No newline at end of file +