From e544601bce373b2f9358ff986c15a98835f50f4b Mon Sep 17 00:00:00 2001 From: Jason Rivard Date: Mon, 8 Jan 2018 11:53:07 -0800 Subject: [PATCH] improve change password page by implementing always enabled submit form --- .../password/pwm/i18n/Admin.properties | 2 +- .../public/resources/js/changepassword.js | 62 ++++++++++++------- .../main/webapp/public/resources/js/main.js | 53 ++++++++-------- 3 files changed, 67 insertions(+), 50 deletions(-) diff --git a/server/src/main/resources/password/pwm/i18n/Admin.properties b/server/src/main/resources/password/pwm/i18n/Admin.properties index 792af4683..391aeec55 100644 --- a/server/src/main/resources/password/pwm/i18n/Admin.properties +++ b/server/src/main/resources/password/pwm/i18n/Admin.properties @@ -332,7 +332,7 @@ EventLog_Narrative_HelpdeskAction=%targetID% (%targetDN%) had an action invoked EventLog_Narrative_HelpdeskClearResponses=Stored responses for %targetID% (%targetDN%) cleared by help desk operator %perpetratorID% (%perpetratorDN%) EventLog_Narrative_HelpdeskClearOtpSecret=OTP secret for %targetID% (%targetDN%) cleared by help desk operator %perpetratorID% (%perpetratorDN%) EventLog_Narrative_HelpdeskSetPassword=Password for %targetID% (%targetDN%) set by help desk operator %perpetratorID% (%perpetratorDN%) -EventLog_Narrative_HelpdeskUnlockPassword=password has be unlocked for %targetID% (%targetDN%) by help desk operator %perpetratorID% (%perpetratorDN%) +EventLog_Narrative_HelpdeskUnlockPassword=Password has been unlocked for %targetID% (%targetDN%) by help desk operator %perpetratorID% (%perpetratorDN%) EventLog_Narrative_HelpdeskDeleteUser=%targetID% (%targetDN%) has been deleted by help desk operator %perpetratorID% (%perpetratorDN%) EventLog_Narrative_HelpdeskViewDetail=Details of %targetID% (%targetDN%) have been viewed by help desk operator %perpetratorID% (%perpetratorDN%) EventLog_Narrative_HelpdeskVerifyOtp=OTP secret for %targetID% (%targetDN%) verified by help desk operator %perpetratorID% (%perpetratorDN%) diff --git a/server/src/main/webapp/public/resources/js/changepassword.js b/server/src/main/webapp/public/resources/js/changepassword.js index 8e6b17920..e171b0964 100644 --- a/server/src/main/webapp/public/resources/js/changepassword.js +++ b/server/src/main/webapp/public/resources/js/changepassword.js @@ -33,27 +33,25 @@ var PWM_CHANGEPW = PWM_CHANGEPW || {}; // takes password values in the password fields, sends an http request to the servlet // and then parses (and displays) the response from the servlet. -PWM_CHANGEPW.validatePasswords = function(userDN) +PWM_CHANGEPW.validatePasswords = function(userDN, nextFunction) { - PWM_MAIN.getObject("password_button").disabled = true; - if (PWM_MAIN.getObject("password1").value.length <= 0 && PWM_MAIN.getObject("password2").value.length <= 0) { - PWM_CHANGEPW.updateDisplay(null); - return; - } - if (PWM_GLOBAL['previousP1'] !== PWM_MAIN.getObject("password1").value) { // if p1 is changing, then clear out p2. PWM_MAIN.getObject("password2").value = ""; PWM_GLOBAL['previousP1'] = PWM_MAIN.getObject("password1").value; } - var validationProps = new Array(); + var validationProps = {}; + + validationProps['completeFunction'] = nextFunction ? nextFunction : function () {}; validationProps['messageWorking'] = PWM_MAIN.showString('Display_CheckingPassword'); validationProps['serviceURL'] = PWM_MAIN.addParamToUrl(window.location.pathname, 'processAction','checkPassword'); validationProps['readDataFunction'] = function(){ var returnObj = {}; returnObj['password1'] = PWM_MAIN.getObject("password1").value; returnObj['password2'] = PWM_MAIN.getObject("password2").value; - if (userDN) returnObj['username'] = userDN; + if (userDN) { + returnObj['username'] = userDN; + } return returnObj; }; validationProps['processResultsFunction'] = function(data){ @@ -70,10 +68,6 @@ PWM_CHANGEPW.validatePasswords = function(userDN) PWM_CHANGEPW.updateDisplay = function(resultInfo) { if (!resultInfo) { - var passwordButton = PWM_MAIN.getObject("password_button"); - if (passwordButton !== null) { - passwordButton.disabled = false; - } PWM_MAIN.showSuccess(PWM_MAIN.showString('Display_PasswordPrompt')); PWM_CHANGEPW.markStrength(0); PWM_CHANGEPW.markConfirmationCheck(null); @@ -88,17 +82,12 @@ PWM_CHANGEPW.updateDisplay = function(resultInfo) { } if (resultInfo["passed"] === true) { - //PWM_MAIN.getObject('password2').disabled = false; if (resultInfo["match"] === "MATCH") { - PWM_MAIN.getObject("password_button").disabled = false; PWM_MAIN.showSuccess(message); } else { - PWM_MAIN.getObject("password_button").disabled = true; PWM_MAIN.showInfo(message); } } else { - //PWM_MAIN.getObject('password2').disabled = true; - PWM_MAIN.getObject("password_button").disabled = true; PWM_MAIN.showError(message); } @@ -203,9 +192,36 @@ PWM_CHANGEPW.showPasswordGuide=function() { }); }; -PWM_CHANGEPW.handleChangePasswordSubmit=function() { - PWM_MAIN.showInfo(PWM_MAIN.showString('Display_PleaseWait')); - PWM_VAR['dirtyPageLeaveFlag'] = false; +PWM_CHANGEPW.handleChangePasswordSubmit=function(event) { + console.log('intercepted change password submit'); + PWM_MAIN.cancelEvent(event); + + var nextFunction = function(data) { + console.log('post change password submit handler'); + if (!data || data['data']['passed'] && 'MATCH' === data['data']['match']) { + console.log('submitting password form'); + PWM_VAR['dirtyPageLeaveFlag'] = false; + PWM_MAIN.getObject("changePasswordForm").submit(); + } else { + var match = data['data']['match']; + if ('MATCH' === match || 'EMPTY' === match) { + PWM_MAIN.getObject("password1").focus(); + } else { + PWM_MAIN.getObject("password2").focus(); + } + PWM_MAIN.closeWaitDialog(); + PWM_CHANGEPW.validatePasswords(); + } + }; + + PWM_MAIN.showWaitDialog({ + loadFunction:function(){ + PWM_MAIN.showInfo('\xa0'); + setTimeout(function(){ + PWM_CHANGEPW.validatePasswords(null, nextFunction); + },500); + }} + ); }; PWM_CHANGEPW.doRandomGeneration=function(randomConfig) { @@ -339,8 +355,8 @@ PWM_CHANGEPW.startupChangePasswordPage=function() { PWM_CHANGEPW.validatePasswords(null); }); PWM_MAIN.addEventHandler(changePasswordForm,"submit",function(event){ - PWM_CHANGEPW.handleChangePasswordSubmit(); - PWM_MAIN.handleFormSubmit(changePasswordForm, event); + PWM_CHANGEPW.handleChangePasswordSubmit(event); + //PWM_MAIN.handleFormSubmit(changePasswordForm, event); return false; }); PWM_MAIN.addEventHandler(changePasswordForm,"reset",function(){ diff --git a/server/src/main/webapp/public/resources/js/main.js b/server/src/main/webapp/public/resources/js/main.js index 6abd9fdae..06143a52a 100644 --- a/server/src/main/webapp/public/resources/js/main.js +++ b/server/src/main/webapp/public/resources/js/main.js @@ -1168,7 +1168,7 @@ PWM_MAIN.messageDivFloatHandler = function() { }; PWM_MAIN.pwmFormValidator = function(validationProps, reentrant) { - var CONSOLE_DEBUG = false; + var CONSOLE_DEBUG = true; var serviceURL = validationProps['serviceURL']; var readDataFunction = validationProps['readDataFunction']; @@ -1181,6 +1181,7 @@ PWM_MAIN.pwmFormValidator = function(validationProps, reentrant) { if (CONSOLE_DEBUG) console.log("pwmFormValidator: beginning..."); + //init vars; if (!PWM_VAR['validationCache']) { PWM_VAR['validationCache'] = {}; @@ -1196,7 +1197,7 @@ PWM_MAIN.pwmFormValidator = function(validationProps, reentrant) { if (cachedResult) { processResultsFunction(cachedResult); if (CONSOLE_DEBUG) console.log('pwmFormValidator: processed cached data, exiting'); - completeFunction(); + completeFunction(cachedResult); return; } } @@ -1218,6 +1219,7 @@ PWM_MAIN.pwmFormValidator = function(validationProps, reentrant) { //check to see if a validation is already in progress, if it is then ignore keypress. if (PWM_VAR['validationInProgress'] === true) { + setTimeout(function(){PWM_MAIN.pwmFormValidator(validationProps, true)}, typeWaitTimeMs + 1); if (CONSOLE_DEBUG) console.log('pwmFormValidator: waiting for a previous validation to complete, exiting...'); return; } @@ -1232,30 +1234,29 @@ PWM_MAIN.pwmFormValidator = function(validationProps, reentrant) { }, 5); } - require(["dojo"],function(dojo){ - var formDataString = dojo.toJson(formData); - if (CONSOLE_DEBUG) console.log('FormValidator: sending form data to server... ' + formDataString); - var loadFunction = function(data) { - PWM_VAR['validationInProgress'] = false; - delete PWM_VAR['validationLastType']; - PWM_VAR['validationCache'][formKey] = data; - if (CONSOLE_DEBUG) console.log('pwmFormValidator: successful read, data added to cache'); - PWM_MAIN.pwmFormValidator(validationProps, true); - }; - var options = {}; - options['content'] = formData; - options['ajaxTimeout'] = ajaxTimeout; - options['errorFunction'] = function(error) { - PWM_VAR['validationInProgress'] = false; - if (showMessage) { - PWM_MAIN.showInfo(PWM_MAIN.showString('Display_CommunicationError')); - } - if (CONSOLE_DEBUG) console.log('pwmFormValidator: error connecting to service: ' + errorObj); - processResultsFunction(null); - completeFunction(); - }; - PWM_MAIN.ajaxRequest(serviceURL,loadFunction,options); - }); + var formDataString = JSON.stringify(formData) ; + + if (CONSOLE_DEBUG) console.log('FormValidator: sending form data to server... ' + formDataString); + var loadFunction = function(data) { + PWM_VAR['validationInProgress'] = false; + delete PWM_VAR['validationLastType']; + PWM_VAR['validationCache'][formKey] = data; + if (CONSOLE_DEBUG) console.log('pwmFormValidator: successful read, data added to cache'); + PWM_MAIN.pwmFormValidator(validationProps, true); + }; + var options = {}; + options['content'] = formData; + options['ajaxTimeout'] = ajaxTimeout; + options['errorFunction'] = function(error) { + PWM_VAR['validationInProgress'] = false; + if (showMessage) { + PWM_MAIN.showInfo(PWM_MAIN.showString('Display_CommunicationError')); + } + if (CONSOLE_DEBUG) console.log('pwmFormValidator: error connecting to service: ' + error); + processResultsFunction(null); + completeFunction(null); + }; + PWM_MAIN.ajaxRequest(serviceURL,loadFunction,options); }; PWM_MAIN.preloadImages = function(imgArray){