diff options
Diffstat (limited to 'client/js/controllers/login.js')
| -rw-r--r-- | client/js/controllers/login.js | 75 |
1 files changed, 48 insertions, 27 deletions
diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 2f74414..829fc1d 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -1,39 +1,60 @@ -/* - * 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. - */ /** - * Represents a book. - * @constructor + * The login controler + * @param {$scope} $scope The $scope angular service + * @param {$sce} $sce The $sce angular service + * @param {$http} $http The $http angular service + * @param {Identity} The Identity service + */ -mainApp.controller('loginCtrl', function ($scope,$interval,$sce) +mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity) { - // Define default states - $('#loginModal').modal({backdrop: 'static', keyboard: false}); - $('#loadingLoginButton').hide(); - $('#failedToLoginAlert').hide(); - + // Check for login and define default states + if(!Identity.isAlreadyLogin()){ + $('#loginModal').modal({backdrop: 'static', keyboard: false}); + } + $scope.$on('logoutEvent', function(){ + $('#loginModal').modal({backdrop: 'static', keyboard: false}); + }); + + $('#loadingLoginButton').hide(); + $('#failedToLoginAlert').hide(); + - $('#loginButton').click(function(){ + $scope.loginAction=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(); + + // Function to call to handle result + var responseCallback=function(response){ + + if(response.status!==0){ + // Set reason of fail + $scope.failReason=response.failReason; - $interval( - function() - { - $('#failedToLoginAlert').show(); + // Display the error + $('#failedToLoginAlert').show(); + } + else { + // Else the user is online ! + $('#loginModal').modal('hide'); + } + // Reset button state $('#loginButton').show(); - $('#loadingLoginButton').hide(); - - }, 2000,1); - - - - }); -}) + $('#loadingLoginButton').hide(); + } + + // Try to login + Identity.login(username, password, projectname, responseCallback); + }; + +}]); |
