From 24c9b85849d6d3f1002fdc0227ca8acecdd2d682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Rodr=C3=ADguez=20Ponce?= Date: Tue, 30 Jul 2024 17:06:47 +0200 Subject: [PATCH] Fix a problem with recaptcha not shown sometimes (#8287) 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. Backport #8285. --- .../userfeedback/GnUserfeedbackDirective.js | 16 ++++---- .../userfeedback/GnmdFeedbackDirective.js | 14 ++++--- .../resources/catalog/js/LoginController.js | 37 +++++++++++-------- 3 files changed, 39 insertions(+), 28 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 8a70afa0615..2b784c82079 100644 --- a/web-ui/src/main/resources/catalog/components/userfeedback/GnUserfeedbackDirective.js +++ b/web-ui/src/main/resources/catalog/components/userfeedback/GnUserfeedbackDirective.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001-2016 Food and Agriculture Organization of the + * Copyright (C) 2001-2024 Food and Agriculture Organization of the * United Nations (FAO-UN), United Nations World Food Programme (WFP) * and United Nations Environment Programme (UNEP) * @@ -266,9 +266,9 @@ module.directive( 'gnUserfeedbacknew', ['$http', 'gnUserfeedbackService', '$translate', '$q', - '$rootScope', 'Metadata', 'vcRecaptchaService', 'gnConfig', + '$rootScope', 'Metadata', 'vcRecaptchaService', 'gnConfig', 'gnConfigService', function($http, gnUserfeedbackService, $translate, $q, - $rootScope, Metadata, vcRecaptchaService, gnConfig) { + $rootScope, Metadata, vcRecaptchaService, gnConfig, gnConfigService) { return { restrict: 'AEC', replace: true, @@ -278,10 +278,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; function initRecord(md) { 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 f9ef16a3edf..25d7ecd4a13 100644 --- a/web-ui/src/main/resources/catalog/components/userfeedback/GnmdFeedbackDirective.js +++ b/web-ui/src/main/resources/catalog/components/userfeedback/GnmdFeedbackDirective.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001-2016 Food and Agriculture Organization of the + * Copyright (C) 2001-2024 Food and Agriculture Organization of the * United Nations (FAO-UN), United Nations World Food Programme (WFP) * and United Nations Environment Programme (UNEP) * @@ -49,6 +49,10 @@ scope.isUserFeedbackEnabled = false; gnConfigService.load().then(function(c) { + scope.recaptchaEnabled = + gnConfig['system.userSelfRegistration.recaptcha.enable']; + scope.recaptchaKey = + gnConfig['system.userSelfRegistration.recaptcha.publickey']; var statusSystemRating = gnConfig[gnConfig.key.isRatingUserFeedbackEnabled]; if (statusSystemRating == 'advanced') { @@ -56,10 +60,7 @@ } }); - scope.recaptchaEnabled = - gnConfig['system.userSelfRegistration.recaptcha.enable']; - scope.recaptchaKey = - gnConfig['system.userSelfRegistration.recaptcha.publickey']; + scope.resolveRecaptcha = false; @@ -141,6 +142,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 29fe48b9862..814eeb246e3 100644 --- a/web-ui/src/main/resources/catalog/js/LoginController.js +++ b/web-ui/src/main/resources/catalog/js/LoginController.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001-2016 Food and Agriculture Organization of the + * Copyright (C) 2001-2024 Food and Agriculture Organization of the * United Nations (FAO-UN), United Nations World Food Programme (WFP) * and United Nations Environment Programme (UNEP) * @@ -41,14 +41,14 @@ module.controller('GnLoginController', ['$scope', '$http', '$rootScope', '$translate', '$location', '$window', '$timeout', - 'gnUtilityService', 'gnConfig', 'gnGlobalSettings', + 'gnUtilityService', 'gnConfig', 'gnConfigService', 'gnGlobalSettings', 'vcRecaptchaService', 'gnUrlUtils', '$q', 'gnLangs', function($scope, $http, $rootScope, $translate, $location, $window, $timeout, - gnUtilityService, gnConfig, gnGlobalSettings, + gnUtilityService, gnConfig, gnConfigService, gnGlobalSettings, vcRecaptchaService, gnUrlUtils, $q, gnLangs) { $scope.formAction = '../../signin#' + - $location.path(); + $location.path(); $scope.registrationStatus = null; $scope.sendPassword = false; $scope.password = null; @@ -56,10 +56,20 @@ $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; var redirect = gnUtilityService.getUrlParameter('redirect'); @@ -76,14 +86,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 @@ -166,6 +168,9 @@ title: data, timeout: 0, type: 'danger'}); + if ($scope.recaptchaEnabled) { + vcRecaptchaService.reload(); + } }); }; /**