From 65bcc720596b395298fa281b5b68737d04ffdb8a Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 10 Feb 2016 17:47:01 +0100 Subject: [PATCH] Make Identity module more AngularJs Like ! --- client/index.html | 7 ++-- client/js/controllers/login.js | 16 ++++----- client/js/controllers/status.js | 6 ++-- client/js/requests/identity.js | 52 ----------------------------- client/js/services/Identity.js | 49 +++++++++++++++++++++++++++ client/js/services/sharedProfile.js | 13 -------- client/partials/nav.html | 2 +- 7 files changed, 63 insertions(+), 82 deletions(-) delete mode 100644 client/js/requests/identity.js create mode 100644 client/js/services/Identity.js delete mode 100644 client/js/services/sharedProfile.js diff --git a/client/index.html b/client/index.html index 013b1b4..10eceb3 100644 --- a/client/index.html +++ b/client/index.html @@ -72,10 +72,7 @@ - - - - + @@ -87,4 +84,4 @@ - \ No newline at end of file + diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 751bd09..e9308b8 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -7,7 +7,7 @@ * @param {sharedProfile} sharedProfile The sharedProfile service */ -mainApp.controller('loginCtrl', ['$scope','$sce','$http', 'sharedProfile', function ($scope,$sce, $http, sharedProfile) +mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity) { // Define default states $('#loginModal').modal({backdrop: 'static', keyboard: false}); @@ -24,23 +24,23 @@ mainApp.controller('loginCtrl', ['$scope','$sce','$http', 'sharedProfile', funct var password=$("#loginFormPassword").val(); var projectname=$("#loginFormProjectname").val(); - var result=identity.request.login($http,username, password, projectname); + var result=Identity.login(username, password, projectname); result.then(function (response){ // Parser result - var requestResultObject=identity.requestParser.parseLoginAnswer(response); + var requestResultObject=Identity.parseLoginAnswer(response); // Check for error if(requestResultObject.status!==0){ - //alert(result.data) + $('#failedToLoginAlert').show(); } else { - $('#loginModal').modal('hide'); - sharedProfile.username=username; - sharedProfile.projectname=projectname; - + $('#loginModal').modal('hide'); + Identity.profile.username=username; + Identity.profile.projectname=projectname; + } // Reset button state diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index ce6882e..7425244 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -6,9 +6,9 @@ * @param {$scope} $scope The $scope service from angular * @param {sharedProfile} sharedProfile The sharedProfile build by ourself */ -mainApp.controller('statusCtrl', ['$scope','sharedProfile', function ($scope, sharedProfile) +mainApp.controller('statusCtrl', ['$scope','Identity', function ($scope, Identity) { - $scope.profile=sharedProfile; + $scope.profile=Identity.profile; -}]); \ No newline at end of file +}]); diff --git a/client/js/requests/identity.js b/client/js/requests/identity.js deleted file mode 100644 index be3f4f8..0000000 --- a/client/js/requests/identity.js +++ /dev/null @@ -1,52 +0,0 @@ - -/** - * Client Identity Module - * @namespace identity - */ -var identity = {}; - -/** - * Contain all request who can be send with http request - * @namespace request - */ -identity.request = {}; - -/** - * Contain parser for result of request made by {@link identity.request} - * @namespace request - */ -identity.requestParser = {}; - - -/** - * - * @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 - */ -identity.request.login=function($http,username, password,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 - */ -identity.requestParser.parseLoginAnswer=function(response){ - var requestParserResult={}; - - requestParserResult.status=0; - requestParserResult.data=response.data; - - - // TODO - - - return requestParserResult; -}; - diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js new file mode 100644 index 0000000..2164592 --- /dev/null +++ b/client/js/services/Identity.js @@ -0,0 +1,49 @@ + +mainApp.factory('Identity',[ '$http', function($http){ + var profile={}; + profile.username="None"; + profile.projectname="None"; + + + /** + * + * @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){ + 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; + + + // TODO + + + return requestParserResult; + }; + + + + return { + login: login, + parseLoginAnswer: parseLoginAnswer, + profile: profile + }; + + +}]); diff --git a/client/js/services/sharedProfile.js b/client/js/services/sharedProfile.js deleted file mode 100644 index 6e78cf6..0000000 --- a/client/js/services/sharedProfile.js +++ /dev/null @@ -1,13 +0,0 @@ - -/** - * The sharedProfile service - * It's used to shared the profile between controller - */ -mainApp.factory('sharedProfile',[function(){ - var profile={}; - - profile.username="None"; - profile.projectname="None"; - - return profile; -}]); \ No newline at end of file diff --git a/client/partials/nav.html b/client/partials/nav.html index 786c53b..7c34174 100644 --- a/client/partials/nav.html +++ b/client/partials/nav.html @@ -39,4 +39,4 @@ - \ No newline at end of file +