From 784b25754c6b168a6c015aa39837c34339c88444 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Thu, 4 Feb 2016 13:20:45 +0100 Subject: Add error checking, add method handler for login --- client/js/requests/errors.js | 14 ++++++++++++++ client/js/requests/identity.js | 9 +++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 client/js/requests/errors.js (limited to 'client/js/requests') diff --git a/client/js/requests/errors.js b/client/js/requests/errors.js new file mode 100644 index 0000000..cc9389a --- /dev/null +++ b/client/js/requests/errors.js @@ -0,0 +1,14 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + + +var errors={}; + + +errors.checkForLogin=function(result){ + // TODO + return true; +}; \ No newline at end of file diff --git a/client/js/requests/identity.js b/client/js/requests/identity.js index cad1261..61f06ed 100644 --- a/client/js/requests/identity.js +++ b/client/js/requests/identity.js @@ -1,9 +1,14 @@ // Make Namespace -var identity = {} ; - +var identity = {}; +identity.login=function(username, projectname, password){ + + // Todo + + return "tokens"; +}; -- cgit v1.2.3 From a16df328c05b3ac005a3c05237a069786b8d5d6f Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 5 Feb 2016 17:47:53 +0100 Subject: Make login part dynamic --- client/index.html | 1 - client/js/controllers/login.js | 38 ++++++++++++++++++------------ client/js/requests/errors.js | 14 ------------ client/js/requests/identity.js | 52 +++++++++++++++--------------------------- 4 files changed, 42 insertions(+), 63 deletions(-) delete mode 100644 client/js/requests/errors.js (limited to 'client/js/requests') diff --git a/client/index.html b/client/index.html index fe53069..a4845e8 100644 --- a/client/index.html +++ b/client/index.html @@ -73,7 +73,6 @@ - diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index d08a9f2..07f1d19 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -3,7 +3,7 @@ * Represents a book. * @constructor */ -mainApp.controller('loginCtrl', function ($scope,$interval,$sce) +mainApp.controller('loginCtrl', function ($scope,$interval,$sce, $http) { // Define default states $('#loginModal').modal({backdrop: 'static', keyboard: false}); @@ -12,30 +12,40 @@ mainApp.controller('loginCtrl', function ($scope,$interval,$sce) $('#loginButton').click(function(){ - $('#loginButton').hide(); - $('#loadingLoginButton').show(); - $('#failedToLoginAlert').hide(); - - var result=identity.login($("#loginFormUsername").val(), $("#loginFormProjectname").val(), $("#loginFormPassword").val()); + $('#loginButton').hide(); + $('#loadingLoginButton').show(); + $('#failedToLoginAlert').hide(); - - $interval( - function() - { + var result=identity.request.login($http,$("#loginFormUsername").val(), $("#loginFormProjectname").val(), $("#loginFormPassword").val()); + + + result.then(function (response){ + + // Parser result + var requestResultObject=identity.requestParser.parseLoginAnswer(response); + // Check for error - if(!errors.checkForLogin(result)){ + if(requestResultObject.status!==0){ + //alert(result.data) $('#failedToLoginAlert').show(); } else { $('#loginModal').modal('hide'); } - + // Reset button state $('#loginButton').show(); $('#loadingLoginButton').hide(); - }, 2000,1); - + },function(response){ + + $('#failedToLoginAlert').show(); + // Reset button state + $('#loginButton').show(); + $('#loadingLoginButton').hide(); + }); + + }); }); diff --git a/client/js/requests/errors.js b/client/js/requests/errors.js deleted file mode 100644 index cc9389a..0000000 --- a/client/js/requests/errors.js +++ /dev/null @@ -1,14 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - - -var errors={}; - - -errors.checkForLogin=function(result){ - // TODO - return true; -}; \ No newline at end of file diff --git a/client/js/requests/identity.js b/client/js/requests/identity.js index 61f06ed..59bbcf2 100644 --- a/client/js/requests/identity.js +++ b/client/js/requests/identity.js @@ -1,47 +1,31 @@ // Make Namespace var identity = {}; +identity.request = {}; // Request part +identity.requestParser = {}; // Parser part -identity.login=function(username, projectname, password){ - - // Todo + +identity.request.login=function($http,username, projectname, password){ + var requestResultObject={}; - return "tokens"; + return $http.post('http://localhost.istic-openstack/server/index.php', + $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}), + {headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}}); }; -/* -mainApp.controller('identityCtrl', function($scope, $http) { - - $scope.identityFormData = {}; - - $scope.processForm = function() { - - $http({ - method : 'POST', - url : 'http://148.60.11.31/', - data : $.param($scope.identityFormData), - headers : { 'Content-Type': 'application/x-www-form-urlencoded' } - }) - .success(function(data) { - console.log(data); - - if (!data.success) { - // if not successful, bind errors to error variables - //$scope.errorName = data.errors.name; - //$scope.errorSuperhero = data.errors.superheroAlias; - } else { - // if successful, bind success message to message - //$scope.message = data.message; - } - }); - }; - - +identity.requestParser.parseLoginAnswer=function(response){ + var requestParserResult={}; + + requestParserResult.status=0; + requestParserResult.data=response.data; -});*/ - + // TODO + + + return requestParserResult; +}; -- cgit v1.2.3 From cca5df968e3598b07ee81c1f7f2680f5b9120ec3 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 5 Feb 2016 19:35:38 +0100 Subject: Add sharedProfile service --- client/index.html | 6 +++++- client/js/app.js | 5 ++++- client/js/controllers/login.js | 19 ++++++++++++------- client/js/controllers/status.js | 24 +++++------------------- client/js/requests/identity.js | 2 +- client/js/services/sharedProfile.js | 11 +++++++++++ client/partials/login.html | 2 +- client/partials/nav.html | 4 ++-- 8 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 client/js/services/sharedProfile.js (limited to 'client/js/requests') diff --git a/client/index.html b/client/index.html index a4845e8..013b1b4 100644 --- a/client/index.html +++ b/client/index.html @@ -71,6 +71,9 @@ + + + @@ -79,7 +82,8 @@ - + + diff --git a/client/js/app.js b/client/js/app.js index 0e9c423..96997eb 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -15,4 +15,7 @@ mainApp.config(['$routeProvider', function($routeProvider){ }).otherwise({ redirectTo: '/home' }); -}]); \ No newline at end of file +}]); + + + diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 07f1d19..3447ab1 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -3,24 +3,27 @@ * Represents a book. * @constructor */ -mainApp.controller('loginCtrl', function ($scope,$interval,$sce, $http) +mainApp.controller('loginCtrl', ['$scope','$sce','$http', 'sharedProfile', function ($scope,$sce, $http, sharedProfile) { // Define default states $('#loginModal').modal({backdrop: 'static', keyboard: false}); $('#loadingLoginButton').hide(); $('#failedToLoginAlert').hide(); - + $('#loginButton').click(function(){ $('#loginButton').hide(); $('#loadingLoginButton').show(); $('#failedToLoginAlert').hide(); - var result=identity.request.login($http,$("#loginFormUsername").val(), $("#loginFormProjectname").val(), $("#loginFormPassword").val()); + var username=$("#loginFormUsername").val(); + var password=$("#loginFormPassword").val(); + var projectname=$("#loginFormProjectname").val(); + + var result=identity.request.login($http,username, password, projectname); result.then(function (response){ - // Parser result var requestResultObject=identity.requestParser.parseLoginAnswer(response); @@ -31,21 +34,23 @@ mainApp.controller('loginCtrl', function ($scope,$interval,$sce, $http) } else { $('#loginModal').modal('hide'); + sharedProfile.username=username; + sharedProfile.projectname=projectname; + } // Reset button state $('#loginButton').show(); $('#loadingLoginButton').hide(); },function(response){ - $('#failedToLoginAlert').show(); // Reset button state $('#loginButton').show(); $('#loadingLoginButton').hide(); }); - + }); -}); +}]); diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index 42a54d4..4ffdb6b 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -4,25 +4,11 @@ -mainApp.controller('statusCtrl', function ($scope,$interval,$sce) -{ - $scope.username="John Doe"; - $scope.projectname="Web Server"; - // Update status every 2 seconds - /*$interval(function(){ - var status=identity.fetchStatus(); - $scope.username=status[1]; - $scope.lastconnection=status[2]; - if(status[0] == "1"){ - $scope.connection=$sce.trustAsHtml("Online"); - } - else{ - $scope.connection=$sce.trustAsHtml("Offline"); - } - }, 2000);*/ - +mainApp.controller('statusCtrl', ['$scope','sharedProfile', function ($scope, sharedProfile) +{ + $scope.profile=sharedProfile; + - -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/client/js/requests/identity.js b/client/js/requests/identity.js index 59bbcf2..7a08714 100644 --- a/client/js/requests/identity.js +++ b/client/js/requests/identity.js @@ -6,7 +6,7 @@ identity.requestParser = {}; // Parser part -identity.request.login=function($http,username, projectname, password){ +identity.request.login=function($http,username, password,projectname){ var requestResultObject={}; return $http.post('http://localhost.istic-openstack/server/index.php', diff --git a/client/js/services/sharedProfile.js b/client/js/services/sharedProfile.js new file mode 100644 index 0000000..2a5ab83 --- /dev/null +++ b/client/js/services/sharedProfile.js @@ -0,0 +1,11 @@ + + + +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/login.html b/client/partials/login.html index aa974ab..e0ce876 100644 --- a/client/partials/login.html +++ b/client/partials/login.html @@ -19,7 +19,7 @@
+ placeholder="Project Name" type="text" ng-model="identityFormData.project">
diff --git a/client/partials/nav.html b/client/partials/nav.html index f412597..786c53b 100644 --- a/client/partials/nav.html +++ b/client/partials/nav.html @@ -18,8 +18,8 @@
- \ No newline at end of file + -- cgit v1.2.3