From b81864469dc5f72c87f2765f82f28101c9bcf34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Pu=C5=A1nik?= Date: Fri, 6 Nov 2015 15:21:30 +0100 Subject: Gui support for SAML account merge/upgrade upon first SAML-type login of an existing user. --- js/codeq/aaiLogin.js | 14 +++++++---- js/codeq/change_password.js | 7 +++--- js/codeq/comms.js | 6 +++-- js/codeq/login.js | 27 ++++++++++----------- js/codeq/signup.js | 7 +++--- js/codeq/upgrade_to_aai.js | 58 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+), 26 deletions(-) create mode 100644 js/codeq/upgrade_to_aai.js (limited to 'js/codeq') diff --git a/js/codeq/aaiLogin.js b/js/codeq/aaiLogin.js index 5d4f1c9..ced3b0c 100644 --- a/js/codeq/aaiLogin.js +++ b/js/codeq/aaiLogin.js @@ -3,7 +3,8 @@ */ (function(){ - var jqNavBarRight = $('.nav.navbar-nav.navbar-right'), + var jqScreen = $('#screen_aai_login'), + jqNavBarRight = $('.nav.navbar-nav.navbar-right'), jqNavigationHomeBtn = $('#navigation-home'), jqCancelAaiLogin = $("#cancel_aai_login"), jqDisabledOverlay = $('#disabled'), @@ -25,7 +26,7 @@ }); $('#signed-in-title').html(''); - $('#screen_aai_login').css('display',''); + jqScreen.css('display',''); codeq.comms.connect() .then(function(){ @@ -33,7 +34,12 @@ jqAaiIframe.attr('src', samlLoginUrl); return codeq.comms.samlLogin(); }) - .then(codeq.loginCallbackFunction) + .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); @@ -52,7 +58,7 @@ jqCancelAaiLogin.off('click'); samlLoginUrl = ''; - $("#screen_aai_login").css('display', 'none'); + jqScreen.css('display', 'none'); //re-enable the click listener of the logo jqNavigationHomeBtn.on('click', function(e){ diff --git a/js/codeq/change_password.js b/js/codeq/change_password.js index c08c2d2..6bba0e9 100644 --- a/js/codeq/change_password.js +++ b/js/codeq/change_password.js @@ -3,7 +3,8 @@ */ (function(){ - var jqNew = $("#modalChangePasswordNew"), + var jqScreen = $("#screen_change_pass"), + jqNew = $("#modalChangePasswordNew"), jqVerify = $("#modalChangePasswordVerify"), jqCancelBtn = $("#cancel_change_pass_button"), jqChangePassForm = $('#formChangePassword'); @@ -35,13 +36,13 @@ }); - $("#screen_change_pass").css('display', ''); + jqScreen.css('display', ''); $('#disabled').css('display', 'none'); }, 'exit' : function(){ jqChangePassForm.off('submit'); jqCancelBtn.off('click'); - $("#screen_change_pass").css('display', 'none'); + jqScreen.css('display', 'none'); jqNew.val(''); jqVerify.val(''); } diff --git a/js/codeq/comms.js b/js/codeq/comms.js index 306263c..b5296a8 100644 --- a/js/codeq/comms.js +++ b/js/codeq/comms.js @@ -533,8 +533,10 @@ return ajaxGet(ajaxDataPrefix + 'resources.json'); }, - 'samlLogin': function(){ - return this.send({'action':'saml_login','gui_lang':codeq.getLang()}); + 'samlLogin': function(upgrade_account, upgrade_password){ + if (upgrade_account === undefined) return this.send({'action':'saml_login','gui_lang':codeq.getLang()}); + else if (upgrade_account) return this.send({'action':'saml_login','gui_lang':codeq.getLang(), 'upgrade_account': true, 'upgrade_password': upgrade_password}); + else return this.send({'action':'saml_login','gui_lang':codeq.getLang(), 'upgrade_account': false}); }, 'samlLogout': function(){ diff --git a/js/codeq/login.js b/js/codeq/login.js index b2c39dd..9d899c6 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -3,17 +3,18 @@ */ (function(){ - var jqNavBarRight = $('.nav.navbar-nav.navbar-right'), + var jqScreen = $("#screen_login"), + jqNavBarRight = $('.nav.navbar-nav.navbar-right'), jqNavigationHomeBtn = $('#navigation-home'), jqAAILoginBtn = $('#aai_login_button'), jqSignupBtn = $('#signup_button'), jqSubmitLoginBtn = $("#submit"), - jqDisabled = $('#disabled'); + jqDisabledOverlay = $('#disabled'); //the loginCallbackFunction is used here and in the AAI login as well codeq.loginCallbackFunction = function (data) { - jqDisabled.css('display', 'none'); - jqDisabled.css('cursor', ''); + jqDisabledOverlay.css('display', 'none'); + jqDisabledOverlay.css('cursor', ''); if (data.code !== 0) throw new Error('Login failed, code: ' + data.code + ', message: ' + data.message); //nav signed in... @@ -39,23 +40,21 @@ } codeq.globalStateMachine.transition('language'); - //codeq.activateState('language'); }; var loginFun = function(){ - jqDisabled.css('display', ''); - jqDisabled.css('cursor', 'wait'); + jqDisabledOverlay.css('display', ''); + jqDisabledOverlay.css('cursor', 'wait'); codeq.comms.connect() .then(function () { return codeq.comms.login($('#username').val(), $('#password').val()); }) .then(codeq.loginCallbackFunction) .fail(function (reason) { - jqDisabled.css('display', 'none'); - jqDisabled.css('cursor', ''); - codeq.log.error('Login failed: ' + reason, reason); + jqDisabledOverlay.css('display', 'none'); + jqDisabledOverlay.css('cursor', ''); + codeq.log.error('Login failed: ' + reason); alert('Login request failed: ' + reason); - jqDisabled.css('display', 'none'); }) .done(); }, @@ -88,8 +87,8 @@ } }); //$('#modalLogIn').modal(); - $("#screen_login").css('display', ''); - jqDisabled.css('display', 'none'); + jqScreen.css('display', ''); + jqDisabledOverlay.css('display', 'none'); }, 'exit' : function(){ //remove the listener from the buttons specific to this page @@ -98,7 +97,7 @@ jqSignupBtn.off('click'); jqAAILoginBtn.off('click'); - $("#screen_login").css('display', 'none'); + jqScreen.css('display', 'none'); $("#password").val(''); //re-enable the click listener jqNavigationHomeBtn.on('click', function(e){ diff --git a/js/codeq/signup.js b/js/codeq/signup.js index bafd690..443b500 100644 --- a/js/codeq/signup.js +++ b/js/codeq/signup.js @@ -3,7 +3,8 @@ */ (function(){ - var jqUsername = $("#modalSignUpUsername"), + var jqScreen = $("#screen_signup"), + jqUsername = $("#modalSignUpUsername"), jqName = $("#modalSignUpName"), jqEmail = $("#modalSignUpEmail"), jqPassword = $("#modalSignUpPassword"), @@ -18,7 +19,7 @@ jqNavigationHomeBtn.off('click');//remove the click listener of this element here jqNavBarRight.css('display','none');//hide settings etc. $('#signed-in-title').html(''); - $("#screen_signup").css('display', ''); + jqScreen.css('display', ''); $('#disabled').css('display', 'none'); jqExitSignUpBtn.on('click',function(){ codeq.globalStateMachine.transition('login'); @@ -53,7 +54,7 @@ }); }, 'exit' : function(){ - $("#screen_signup").css('display', 'none'); + jqScreen.css('display', 'none'); //re-enable the click listener jqNavigationHomeBtn.on('click', function(e){ codeq.globalStateMachine.transition('language'); diff --git a/js/codeq/upgrade_to_aai.js b/js/codeq/upgrade_to_aai.js new file mode 100644 index 0000000..31c581a --- /dev/null +++ b/js/codeq/upgrade_to_aai.js @@ -0,0 +1,58 @@ +/** + * Created by markop on 11/02/15. + */ +(function(){ + + var jqScreen = $("#screen_upgrade_to_aai"), + jqForm = $('#formUpgradeToAAI'), + jqNoBtn = $('#btnUpgradeToAAINo'), + jqPassword = $('#formUpgradeToAAIPassword') ; + + codeq.globalStateMachine.register('upgradeToAAI',{ + 'enter': function(){ + jqNoBtn.on('click',function(){ + codeq.comms.samlLogin(false) + .then(codeq.loginCallbackFunction) + .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(); + }); + jqForm.on('submit',function(event) { + event.preventDefault(); // Prevent the form from submitting via the browser. + codeq.comms.samlLogin(true, jqPassword.val()) + .then(function(data){ + // password does not match + if (data.code == 4) { + codeq.log.error('code: ' + data.code + ', message: ' + data.message); + alert('Password does not match. Enter right password or select No.'); + } + //ok or other + 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(); + + }); + jqScreen.css('display', ''); + $('#disabled').css('display', 'none'); + }, + 'exit' : function(){ + jqNoBtn.off('click'); + jqForm.off('submit'); + jqScreen.css('display', 'none'); + jqPassword.val(''); + } + }); + +})(); -- cgit v1.2.1