Skip to content

Commit

Permalink
Fix a problem with recaptcha not shown sometimes (geonetwork#8287)
Browse files Browse the repository at this point in the history
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 geonetwork#8285.
  • Loading branch information
juanluisrp authored Jul 30, 2024
1 parent d0bb9de commit 24c9b85
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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)
*
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
*
Expand Down Expand Up @@ -49,17 +49,18 @@
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') {
scope.isUserFeedbackEnabled = true;
}
});

scope.recaptchaEnabled =
gnConfig['system.userSelfRegistration.recaptcha.enable'];
scope.recaptchaKey =
gnConfig['system.userSelfRegistration.recaptcha.publickey'];

scope.resolveRecaptcha = false;


Expand Down Expand Up @@ -141,6 +142,9 @@
scope.mdFeedbackOpen = false;
} else {
scope.success = false;
if (scope.recaptchaEnabled) {
vcRecaptchaService.reload();
}
}
});
}
Expand Down
37 changes: 21 additions & 16 deletions web-ui/src/main/resources/catalog/js/LoginController.js
Original file line number Diff line number Diff line change
@@ -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)
*
Expand Down Expand Up @@ -41,25 +41,35 @@
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;
$scope.passwordCheck = null;
$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');
Expand All @@ -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
Expand Down Expand Up @@ -166,6 +168,9 @@
title: data,
timeout: 0,
type: 'danger'});
if ($scope.recaptchaEnabled) {
vcRecaptchaService.reload();
}
});
};
/**
Expand Down

0 comments on commit 24c9b85

Please sign in to comment.