From 3f83cae4178226084dcbf1e826271a04cc97086d Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 10 Feb 2016 21:45:52 +0100 Subject: Login Service complete ! --- client/js/controllers/login.js | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'client/js/controllers/login.js') 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); + }); + }]); -- cgit v1.2.3