summaryrefslogtreecommitdiff
path: root/client/js/controllers/login.js
blob: 07f1d1948ee4e618e796ac7c03a26a961a0109b6 (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

/**
 * Represents a book.
 * @constructor
 */
mainApp.controller('loginCtrl', function ($scope,$interval,$sce, $http)
{
    // 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());
        
        
        result.then(function (response){
            
            // Parser result
            var requestResultObject=identity.requestParser.parseLoginAnswer(response);
            
            // Check for error
            if(requestResultObject.status!==0){
                //alert(result.data)
                $('#failedToLoginAlert').show();
            }
            else {
                $('#loginModal').modal('hide');
            }

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

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