Skip to content

Commit

Permalink
localize friendly captcha (#1006)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Jan 9, 2025
1 parent 25bb1bf commit 6873eda
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/developpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Here is a template example of such a captcha module:
}
# Function that generate the html part containing the captcha
function generate_html_captcha($messages){
function generate_html_captcha($messages, $lang){
$captcha_html ='
<div class="row mb-3">
Expand Down
2 changes: 1 addition & 1 deletion htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
$captcha_css = '';
if(isset($use_captcha) && $use_captcha == true)
{
$captcha_html = $captchaInstance->generate_html_captcha($messages);
$captcha_html = $captchaInstance->generate_html_captcha($messages, $lang);
$captcha_js = $captchaInstance->generate_js_captcha();
$captcha_css = $captchaInstance->generate_css_captcha();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/captcha/FriendlyCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ function generate_js_captcha(){
}

# Function that generate the html part containing the captcha
function generate_html_captcha($messages){
function generate_html_captcha($messages, $lang){

$captcha_html ='
<div class="row mb-3">
<div class="col-sm-4 col-form-label text-end captcha">
</div>
<div class="col-sm-8">
<div class="frc-captcha" data-sitekey="'.$this->friendlycaptcha_sitekey.'"></div>
<div class="frc-captcha" data-sitekey="'.$this->friendlycaptcha_sitekey.'" data-lang="'.$lang.'"></div>
</div>
</div>';

Expand Down
2 changes: 1 addition & 1 deletion lib/captcha/InternalCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function generate_js_captcha(){
}

# Function that generate the html part containing the captcha
function generate_html_captcha($messages){
function generate_html_captcha($messages, $lang){

$captcha_html ='
<div class="row mb-3">
Expand Down
2 changes: 1 addition & 1 deletion lib/captcha/ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function generate_js_captcha(){
}

# Function that generate the html part containing the captcha
function generate_html_captcha($messages){
function generate_html_captcha($messages, $lang){

$captcha_html ='
<div class="row mb-3">
Expand Down
4 changes: 2 additions & 2 deletions tests/FriendlyCaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function test_generate_html_captcha(): void
$friendlycaptcha_sitekey,
$friendlycaptcha_secret);

$html = $captchaInstance->generate_html_captcha($messages);
$html = $captchaInstance->generate_html_captcha($messages, "en");

$this->assertMatchesRegularExpression('/<div class="frc-captcha" data-sitekey="'.$friendlycaptcha_sitekey.'">/',$html, "dummy challenge in html code");
$this->assertMatchesRegularExpression('/<div class="frc-captcha" data-sitekey="'.$friendlycaptcha_sitekey.'" data-lang="en">/',$html, "dummy challenge in html code");
}

public function test_verify_captcha_challenge_ok(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/InternalCaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function test_generate_html_captcha(): void
->method('generate_captcha_challenge')
->will($this->returnValue("my-challenge"));

$html = $captchaMock->generate_html_captcha($messages);
$html = $captchaMock->generate_html_captcha($messages, "en");

$this->assertMatchesRegularExpression('/<img src="my-challenge"/',$html, "dummy challenge in html code");
$this->assertMatchesRegularExpression('/<input type="text" autocomplete="new-password" name="captchaphrase" id="captchaphrase" class="form-control" placeholder="Captcha"/',$html, "dummy captcha input box in html code");
Expand Down
2 changes: 1 addition & 1 deletion tests/ReCaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function test_generate_html_captcha(): void
$recaptcha_secretkey,
$recaptcha_minscore);

$html = $captchaInstance->generate_html_captcha($messages);
$html = $captchaInstance->generate_html_captcha($messages, "en");

$this->assertMatchesRegularExpression('/<input type="hidden" autocomplete="new-password" name="captchaphrase" id="captchaphrase" class="form-control"/',$html, "dummy challenge in html code");
}
Expand Down

0 comments on commit 6873eda

Please sign in to comment.