From aa525736c20055ed8d0a102f1e4ed20068753a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Rodr=C3=ADguez=20Ponce?= Date: Tue, 30 Jul 2024 15:55:17 +0200 Subject: [PATCH] Fix a problem with recaptcha not shown sometimes (#8285) In the register user, metadata feedback and user feedback forms, sometimes the settings with the recaptcha keys takes a bit longer to load making the recaptcha widget not to load. This commit fixes that updating the values of the recaptcha settings when the settings have finished loading. It also resets the recaptcha widget if there is any problem returned by the server after sending the form. --- .../userfeedback/GnUserfeedbackDirective.js | 14 +++++--- .../userfeedback/GnmdFeedbackDirective.js | 3 ++ .../resources/catalog/js/LoginController.js | 35 ++++++++++++------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/web-ui/src/main/resources/catalog/components/userfeedback/GnUserfeedbackDirective.js b/web-ui/src/main/resources/catalog/components/userfeedback/GnUserfeedbackDirective.js index de197b907ac..80d6c7964e6 100644 --- a/web-ui/src/main/resources/catalog/components/userfeedback/GnUserfeedbackDirective.js +++ b/web-ui/src/main/resources/catalog/components/userfeedback/GnUserfeedbackDirective.js @@ -303,6 +303,7 @@ "Metadata", "vcRecaptchaService", "gnConfig", + "gnConfigService", function ( $http, gnUserfeedbackService, @@ -311,7 +312,8 @@ $rootScope, Metadata, vcRecaptchaService, - gnConfig + gnConfig, + gnConfigService ) { return { restrict: "AEC", @@ -322,10 +324,12 @@ templateUrl: "../../catalog/components/" + "userfeedback/partials/userfeedbacknew.html", link: function (scope) { - scope.recaptchaEnabled = - gnConfig["system.userSelfRegistration.recaptcha.enable"]; - scope.recaptchaKey = - gnConfig["system.userSelfRegistration.recaptcha.publickey"]; + gnConfigService.loadPromise.then(function () { + scope.recaptchaEnabled = + gnConfig["system.userSelfRegistration.recaptcha.enable"]; + scope.recaptchaKey = + gnConfig["system.userSelfRegistration.recaptcha.publickey"]; + }); scope.resolveRecaptcha = false; scope.userName = null; diff --git a/web-ui/src/main/resources/catalog/components/userfeedback/GnmdFeedbackDirective.js b/web-ui/src/main/resources/catalog/components/userfeedback/GnmdFeedbackDirective.js index 9405de99f71..f693181de2a 100644 --- a/web-ui/src/main/resources/catalog/components/userfeedback/GnmdFeedbackDirective.js +++ b/web-ui/src/main/resources/catalog/components/userfeedback/GnmdFeedbackDirective.js @@ -139,6 +139,9 @@ scope.mdFeedbackOpen = false; } else { scope.success = false; + if (scope.recaptchaEnabled) { + vcRecaptchaService.reload(); + } } }); } diff --git a/web-ui/src/main/resources/catalog/js/LoginController.js b/web-ui/src/main/resources/catalog/js/LoginController.js index 9a6a5de8f80..42097136212 100644 --- a/web-ui/src/main/resources/catalog/js/LoginController.js +++ b/web-ui/src/main/resources/catalog/js/LoginController.js @@ -45,6 +45,7 @@ "$window", "$timeout", "gnUtilityService", + "gnConfigService", "gnConfig", "gnGlobalSettings", "vcRecaptchaService", @@ -59,6 +60,7 @@ $window, $timeout, gnUtilityService, + gnConfigService, gnConfig, gnGlobalSettings, vcRecaptchaService, @@ -73,8 +75,23 @@ $scope.userToRemind = null; $scope.changeKey = null; - $scope.recaptchaEnabled = gnConfig["system.userSelfRegistration.recaptcha.enable"]; - $scope.recaptchaKey = gnConfig["system.userSelfRegistration.recaptcha.publickey"]; + gnConfigService.loadPromise.then(function () { + $scope.recaptchaEnabled = + gnConfig["system.userSelfRegistration.recaptcha.enable"]; + $scope.recaptchaKey = gnConfig["system.userSelfRegistration.recaptcha.publickey"]; + + // take the bigger of the two values + $scope.passwordMinLength = Math.max( + gnConfig["system.security.passwordEnforcement.minLength"], + 6 + ); + $scope.passwordMaxLength = Math.max( + gnConfig["system.security.passwordEnforcement.maxLength"], + 6 + ); + $scope.passwordPattern = gnConfig["system.security.passwordEnforcement.pattern"]; + }); + $scope.resolveRecaptcha = false; $scope.redirectUrl = gnUtilityService.getUrlParameter("redirect"); @@ -84,17 +101,6 @@ $scope.isShowLoginAsLink = gnGlobalSettings.isShowLoginAsLink; $scope.isUserProfileUpdateEnabled = gnGlobalSettings.isUserProfileUpdateEnabled; - // take the bigger of the two values - $scope.passwordMinLength = Math.max( - gnConfig["system.security.passwordEnforcement.minLength"], - 6 - ); - $scope.passwordMaxLength = Math.max( - gnConfig["system.security.passwordEnforcement.maxLength"], - 6 - ); - $scope.passwordPattern = gnConfig["system.security.passwordEnforcement.pattern"]; - function initForm() { if ($window.location.pathname.indexOf("new.password") !== -1) { // Retrieve username from URL parameter @@ -196,6 +202,9 @@ timeout: 0, type: "danger" }); + if ($scope.recaptchaEnabled) { + vcRecaptchaService.reload(); + } } ); };