summaryrefslogtreecommitdiff
path: root/client/js/controllers/login.js
blob: e9308b8cc223e3ad12bee37bd070b20f248b2ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

/**
 * 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 {sharedProfile} sharedProfile The sharedProfile service

 */
mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity)
{
    // Define default states
    $('#loginModal').modal({backdrop: 'static', keyboard: false});
    $('#loadingLoginButton').hide();
    $('#failedToLoginAlert').hide();

     
    $('#loginButton').click(function(){
        $('#loginButton').hide();
        $('#loadingLoginButton').show();
        $('#failedToLoginAlert').hide();

        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 requestResultObject=Identity.parseLoginAnswer(response);
            
            // Check for error
            if(requestResultObject.status!==0){
                
                $('#failedToLoginAlert').show();
            }
            else {
				$('#loginModal').modal('hide');
                Identity.profile.username=username;
				Identity.profile.projectname=projectname;
				
            }

            // Reset button state
            $('#loginButton').show();
            $('#loadingLoginButton').hide();
        },function(response){
            $('#failedToLoginAlert').show();

            // Reset button state
            $('#loginButton').show();
            $('#loadingLoginButton').hide();
        });

      
        
     });
}]);