/* CodeQ: an online programming tutor. Copyright (C) 2015 UL FRI This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ /** * Created by robert on 10/14/15. * */ (function(){ "use strict"; 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',{ 'jqScreen': jqScreen, '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',''); } }); })();