Skip to content

[OJS][main] ReCAPTCHA on the reset password form. #11232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions classes/template/PKPTemplateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ public function initialize(PKPRequest $request)
if (Config::getVar('captcha', 'captcha_on_login')) {
array_push($contexts, 'frontend-login-index', 'frontend-login-signIn');
}
if (Config::getVar('captcha', 'captcha_on_lost_password')) {
array_push($contexts, 'frontend-login-lostPassword', 'frontend-login-requestResetPassword');
}
if (count($contexts)) {
// These are the supported locales: https://developers.google.com/recaptcha/docs/language
// It seems Google has already mapping for locales missing in that list, so that we can provide locale es it is.
Expand Down Expand Up @@ -1030,7 +1033,7 @@ public function setupBackendPage()
];
$isNewSubmissionLinkPresent = true;
}

$menu['dashboards'] = [
'name' => __('navigation.dashboards'),
'icon' => 'Dashboard',
Expand Down Expand Up @@ -1380,15 +1383,15 @@ public function display($template = null, $cache_id = null, $compile_id = null,
];

if($context) {
$pageContext = array_merge($pageContext, [
$pageContext = array_merge($pageContext, [
'dateFormatShort' => PKPString::convertStrftimeFormat($context->getLocalizedDateFormatShort()),
'dateFormatLong' => PKPString::convertStrftimeFormat($context->getLocalizedDateFormatLong()),
'datetimeFormatShort' => PKPString::convertStrftimeFormat($context->getLocalizedDateTimeFormatShort()),
'datetimeFormatLong' => PKPString::convertStrftimeFormat($context->getLocalizedDateTimeFormatLong()),
'timeFormat' => PKPString::convertStrftimeFormat($context->getLocalizedTimeFormat()),
]);
} else {
$pageContext = array_merge($pageContext, [
$pageContext = array_merge($pageContext, [
'dateFormatShort' => PKPString::convertStrftimeFormat(Config::getVar('general', 'date_format_short')),
'dateFormatLong' => PKPString::convertStrftimeFormat(Config::getVar('general', 'date_format_long')),
'datetimeFormatShort' => PKPString::convertStrftimeFormat(Config::getVar('general', 'datetime_format_short')),
Expand Down
16 changes: 16 additions & 0 deletions pages/login/LoginHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ public function lostPassword($args, $request)
$this->setupTemplate($request);
$templateMgr = TemplateManager::getManager($request);

$isCaptchaEnabled = Config::getVar('captcha', 'recaptcha') && Config::getVar('captcha', 'captcha_on_lost_password');
if ($isCaptchaEnabled) {
$templateMgr->assign('recaptchaPublicKey', Config::getVar('captcha', 'recaptcha_public_key'));
}

$this->_generateAltchaComponent('altcha_on_lost_password', $templateMgr);
$templateMgr->display('frontend/pages/userLostPassword.tpl');
}
Expand All @@ -226,6 +231,17 @@ public function requestResetPassword($args, $request)
$this->setupTemplate($request);
$templateMgr = TemplateManager::getManager($request);

$isCaptchaEnabled = Config::getVar('captcha', 'recaptcha') && Config::getVar('captcha', 'captcha_on_lost_password');
$recaptchaError = null;
if ($isCaptchaEnabled) {
$templateMgr->assign('recaptchaPublicKey', Config::getVar('captcha', 'recaptcha_public_key'));
try {
FormValidatorReCaptcha::validateResponse($request->getUserVar('g-recaptcha-response'), $request->getRemoteAddr(), $request->getServerHost());
} catch (Exception $exception) {
$recaptchaError = 'common.captcha.error.missing-input-response';
}
}

$altchaHasError = $this->_validateAltchasResponse($request, 'altcha_on_lost_password');

if ($altchaHasError) {
Expand Down
13 changes: 12 additions & 1 deletion templates/frontend/pages/userLostPassword.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
</label>
</div>

{if $recaptchaPublicKey}
<fieldset class="recaptcha_wrapper">
<div class="fields">
<div class="recaptcha">
<div class="g-recaptcha" data-sitekey="{$recaptchaPublicKey|escape}">
</div><label for="g-recaptcha-response" style="display:none;" hidden>Recaptcha response</label>
</div>
</div>
</fieldset>
{/if}

{* altcha spam blocker *}
{if $altchaEnabled}
<fieldset class="altcha_wrapper">
Expand All @@ -48,7 +59,7 @@
</div>
</fieldset>
{/if}

<div class="buttons">
<button class="submit" type="submit">
{translate key="user.login.resetPassword"}
Expand Down