summaryrefslogtreecommitdiff
path: root/js/codeq/aaiLogin.js
blob: 99cf7a3fbc4e60e1af61a17af67d938a4feb3e10 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
 * Created by robert on 10/14/15.
 */
(function(){

    var jqScreen = $('#screen_aai_login'),
        jqNavBarRight = $('.nav.navbar-nav.navbar-right'),
        jqNavigationHomeBtn = $('#navigation-home'),
        jqCancelAaiLogin = $("#cancel_aai_login"),
        jqDisabledOverlay = $('#disabled'),
        jqAaiIframe = $('#aai_iframe'),
        baseSamlUrl = 'https://codeq.si/saml/Login?sid=',
        samlLoginUrl = '';

    codeq.globalStateMachine.register('aailogin',{
        'enter': function(){
            jqDisabledOverlay.css('display', '');
            codeq.samlLogin = true;//set the flag
            $('.saml-login-hide').css('display','none');//hide the change password buttons, in the case we go back to the normal login page (cancel or error) they will be reset to being visible when we enter the normal login state
            jqNavigationHomeBtn.off('click');//remove the click listener of this element here
            jqNavBarRight.css('display','none');//hide settings etc.

            //enable the back button
            jqCancelAaiLogin.on('click',function(){
                codeq.globalStateMachine.transition('login');
            });

            $('#signed-in-title').html('');
            jqScreen.css('display','');

            codeq.comms.connect()
                .then(function(){
                    samlLoginUrl = baseSamlUrl + codeq.comms.getSid();
                    jqAaiIframe.attr('src', samlLoginUrl);
                    return codeq.comms.samlLogin();
                })
                .then(function(data){
                    //upgrade
                    if (data.code == 1) codeq.globalStateMachine.transition('upgradeToAAI');
                    //not upgrade
                    else codeq.loginCallbackFunction(data);
                })
                .fail(function(reason){
                    if(codeq.samlLogin){//if the user goes back to the normal login screen the timeout (which will happen) mustn't do anything
                        codeq.log.error('SAML login failed: ' + reason);
                        alert('SAML login failed: ' + reason);
                        codeq.globalStateMachine.transition('login');
                    }
                })
                .done();

            jqDisabledOverlay.css('display','none');
        },
        'exit' : function(){
            //disable site specific listeners
            codeq.comms.off('saml_login');
            jqAaiIframe.attr('src','');//lets remove the url
            jqCancelAaiLogin.off('click');
            samlLoginUrl = '';

            jqScreen.css('display', 'none');

            //re-enable the click listener of the logo
            jqNavigationHomeBtn.on('click', function(e){
                codeq.globalStateMachine.transition('language');
                e.preventDefault();
            });
            //show the menu buttons
            jqNavBarRight.css('display','');
        }
    });

})();