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/js/controllers/login.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'client/js/controllers') 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(); + }); + + }); }); -- cgit v1.2.3