Skip to content

Commit

Permalink
Fix a problem with recaptcha not shown sometimes (#8285)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
juanluisrp authored Jul 30, 2024
1 parent f9d8f0d commit aa52573
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
"Metadata",
"vcRecaptchaService",
"gnConfig",
"gnConfigService",
function (
$http,
gnUserfeedbackService,
Expand All @@ -311,7 +312,8 @@
$rootScope,
Metadata,
vcRecaptchaService,
gnConfig
gnConfig,
gnConfigService
) {
return {
restrict: "AEC",
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
scope.mdFeedbackOpen = false;
} else {
scope.success = false;
if (scope.recaptchaEnabled) {
vcRecaptchaService.reload();
}
}
});
}
Expand Down
35 changes: 22 additions & 13 deletions web-ui/src/main/resources/catalog/js/LoginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"$window",
"$timeout",
"gnUtilityService",
"gnConfigService",
"gnConfig",
"gnGlobalSettings",
"vcRecaptchaService",
Expand All @@ -59,6 +60,7 @@
$window,
$timeout,
gnUtilityService,
gnConfigService,
gnConfig,
gnGlobalSettings,
vcRecaptchaService,
Expand All @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -196,6 +202,9 @@
timeout: 0,
type: "danger"
});
if ($scope.recaptchaEnabled) {
vcRecaptchaService.reload();
}
}
);
};
Expand Down

0 comments on commit aa52573

Please sign in to comment.