Skip to content

Commit 0f59b84

Browse files
committed
support hCaptcha - v1.0.1pre-alpha
support hCaptcha - v1.0.1pre-alpha
1 parent c1bb356 commit 0f59b84

File tree

8 files changed

+233
-30
lines changed

8 files changed

+233
-30
lines changed

CIMultiCaptcha/Config/MultiCaptchaCIConfig.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
* @author Pooya Parsa Dadashi(@datamweb)
1313
* @link https://datamweb.ir
1414
* @github_link https://github.com/datamweb/CodeIgniter-Multi-Captcha
15-
* @since Version 1.0.0-pre-alpha
16-
* @datepublic 2022-02-22 | 1400/12/03
15+
* @since Version 1.0.1-pre-alpha
16+
* @datepublic 2022-02-23 | 1400/12/04
1717
*
1818
*/
19-
2019
class MultiCaptchaCIConfig extends BaseConfig
2120
{
2221

@@ -28,7 +27,7 @@ class MultiCaptchaCIConfig extends BaseConfig
2827
'secret_key' => "Set_ARCaptcha_Secret_Key", //Required. Your account secret key.
2928
//Enable more customization ArCaptcha .
3029
'color' => '#119744', //Optional. Set color of every colored element in widget.color name or hex code;
31-
//'lang' => 'fa', //Optional. Set language of widget . Defaults to fa.(en | fa)
30+
'lang' => '', //Optional(en | fa) : Set language of widget . Defaults CI lang .
3231
'size' => 'normal', //Optional. Set the size of the widget. Defaults to normal.(normal | inivisible)
3332
'theme' => 'light', //Optional. Set the theme of widget. Defualts to light.(light | dark)
3433
'callback' => '', //Optional. Called when the user submits a successful response. The arcaptcha-token token is passed to your callback.(<function name>)
@@ -43,7 +42,7 @@ class MultiCaptchaCIConfig extends BaseConfig
4342
'site_key' => "Set_biBot_Site_Key", //Required. The sitekey you expect to see.
4443
'secret_key' => "Set_biBot_Secret_Key", //Required. Your account secret key.
4544
//bibot-captcha tag attributes
46-
//'lang' => 'fa', //fa | en
45+
'lang' => '', //Optional :: fa | en (Defaults CI lang)
4746
'callback' => '',
4847
//No need to change.
4948
'BaseURI' => 'https://api.bibot.ir/', //Required.Api Base Uri
@@ -55,6 +54,7 @@ class MultiCaptchaCIConfig extends BaseConfig
5554
public $reCaptcha=[
5655
'site_key' => "Set_reCaptcha_Site_Key", //Required. The sitekey you expect to see.
5756
'secret_key' => "Set_reCaptcha_Secret_Key", //Required. Your account secret key.
57+
'lang' => '', //Optional :: fa | en (Defaults CI lang)
5858
// g-recaptcha tag attributes
5959
'theme' => 'light', //dark | light
6060
'size' => 'normal', //compact | normal
@@ -67,4 +67,25 @@ class MultiCaptchaCIConfig extends BaseConfig
6767
'ScriptURL' => 'https://www.google.com/recaptcha/api.js', //Required for run api
6868
];
6969

70+
//Config hCaptcha''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
71+
//You can get that at https://dashboard.hcaptcha.com/settings and register then get the SiteKey and SecretKey from the hcaptcha panel.
72+
public $hCaptcha=[
73+
'site_key' => "Set_hCaptcha_Site_Key", //Required. The sitekey you expect to see.
74+
'secret_key' => "Set_hCaptcha_Site_Key", //Required. Your account secret key.
75+
'lang' => '', //Optional :: fa | en and https://docs.hcaptcha.com/languages (Defaults CI lang)
76+
// h-captcha tag attributes
77+
'theme' => 'light', //dark | light
78+
'size' => 'normal', //compact | normal
79+
'tabindex' => '', //Optional. Set the tabindex of the widget and popup. When appropriate, can make navigation more intuitive on your site. Defaults to 0.
80+
'callback' => '', //Optional. Called when the user submits a successful response. The h-captcha-response token is passed to your callback.
81+
'expired_callback' => '', //Optional. Called when the passcode response expires and the user must re-verify.
82+
'chalexpired_callback' => '', //Optional. Called when the user display of a challenge times out with no answer.
83+
'open_callback' => '', //Optional. Called when the user display of a challenge starts.
84+
'close_callback' => '', //Optional. Called when the user dismisses a challenge.
85+
'error_callback' => '', //Optional. Called when hCaptcha encounters an error and cannot continue. If you specify an error callback, you must inform the user that they should retry. Please see https://docs.hcaptcha.com/configuration#error-codes.
86+
//No need to change.
87+
'BaseURI' => 'https://hcaptcha.com/', //Required.Api Base Uri
88+
'ScriptURL' => 'https://js.hcaptcha.com/1/api.js', //Required for run api
89+
];
90+
7091
}

CIMultiCaptcha/Config/Services.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* @author Pooya Parsa Dadashi(@datamweb)
1515
* @link https://datamweb.ir
1616
* @github_link https://github.com/datamweb/CodeIgniter-Multi-Captcha
17-
* @since Version 1.0.0
18-
* @datepublic 2022-02-19 | 1400/11/30
17+
* @since Version 1.0.1-pre-alpha
18+
* @datepublic 2022-02-23 | 1400/12/04
1919
*
2020
*/
2121

CIMultiCaptcha/Helpers/ci_multi_captcha_helper.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* @author Pooya Parsa Dadashi(@datamweb)
1111
* @link https://datamweb.ir
1212
* @github_link https://github.com/datamweb/CodeIgniter-Multi-Captcha
13-
* @since Version 1.0.0-pre-alpha
14-
* @datepublic 2022-02-22 | 1400/12/03
13+
* @since Version 1.0.1-pre-alpha
14+
* @datepublic 2022-02-23 | 1400/12/04
1515
*
1616
*/
1717
/*
@@ -32,6 +32,8 @@
3232
* *bibot :: <script src="%s"></script>
3333
* *arcaptcha :: <script src="%s" async defer></script>
3434
* *recaptcha :: <script src="%s?hl=%s"></script>
35+
* *hcaptcha :: <script src="%s?hl=%s"></script>
36+
*
3537
*/
3638
if (! function_exists('CIMC_JS'))
3739
{
@@ -47,6 +49,8 @@ function CIMC_JS(string $CaptchaName ='arcaptcha') : string
4749
* *bibot :: <div class="bibot-captcha" data-sitekey="%s" data-lang="%s" data-callback="%s"></div>
4850
* *arcaptcha :: <div class="arcaptcha" data-site-key="%s" data-color="%s" data-lang="%s" data-size="%s" data-theme="%s" data-callback="%s"></div>
4951
* *recaptcha :: <div class="g-recaptcha" data-sitekey="%s" data-theme="%s" data-size="%s" data-tabindex="%s" data-callback="%s" data-expired-callback="%s" data-error-callback="%s"></div>
52+
* *hcaptcha :: <div class="h-captcha" data-sitekey="%s" data-theme="%s" data-size="%s" data-tabindex="%s" data-callback="%s" data-expired-callback="%s" data-error-callback="%s"></div>
53+
*
5054
*/
5155
if (! function_exists('CIMC_HTML'))
5256
{
@@ -62,6 +66,7 @@ function CIMC_HTML(array $options = ['captcha_name'=>'arcaptcha']) : string
6266
* *bibot-response
6367
* *arcaptcha-token
6468
* *g-recaptcha-response
69+
* *h-captcha-response
6570
*/
6671
if (! function_exists('CIMC_FIELD'))
6772
{
@@ -76,6 +81,8 @@ function CIMC_FIELD(string $CaptchaListName='arcaptcha')
7681
* *bibot
7782
* *arcaptcha
7883
* *recaptcha
84+
* *hcaptcha
85+
*
7986
*/
8087
if (! function_exists('CIMC_RULE'))
8188
{
@@ -103,6 +110,10 @@ function CIMC_ERROR()
103110
// show recaptcha errore by CIMC_ERRORS_SINGLE templates
104111
return $validation->showError('g-recaptcha-response','CIMC_ERRORS_SINGLE');
105112
}
113+
if ($validation->hasError('h-captcha-response')) {
114+
// show hcaptcha errore by CIMC_ERRORS_SINGLE templates
115+
return $validation->showError('h-captcha-response','CIMC_ERRORS_SINGLE');
116+
}
106117
if ($validation->hasError('arcaptcha-token')) {
107118
// show arcaptcha errore by CIMC_ERRORS_SINGLE templates
108119
return $validation->showError('arcaptcha-token','CIMC_ERRORS_SINGLE');

CIMultiCaptcha/Helpers/cimc_arcaptcha_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* @author Pooya Parsa Dadashi(@datamweb)
1111
* @link https://datamweb.ir
1212
* @github_link https://github.com/datamweb/CodeIgniter-Multi-Captcha
13-
* @since Version 1.0.0-pre-alpha
14-
* @datepublic 2022-02-19 | 1400/11/30
13+
* @since Version 1.0.1-pre-alpha
14+
* @datepublic 2022-02-23 | 1400/12/04
1515
*
1616
*/
1717

CIMultiCaptcha/Language/en/MultiCaptchaCILang.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* @author Pooya Parsa Dadashi
1010
* @link https://datamweb.ir
1111
* @github_link https://github.com/datamweb/CodeIgniter-Multi-Captcha
12-
* @since Version 1.0.0-pre-alpha
13-
* @datepublic 2022-02-22 | 1400/12/03
12+
* @since Version 1.0.1-pre-alpha
13+
* @datepublic 2022-02-23 | 1400/12/04
1414
*
1515
*/
1616

@@ -78,5 +78,26 @@
7878
//if required use filde name set
7979
'g-recaptcha-response' => "I'm not a robot(recaptcha)",
8080
],
81+
// Custom Validation language for hCaptcha
82+
'hCaptcha'=> [
83+
'errors' => [
84+
'unknown' => 'The system detected you as a robot for some reason, try again.',
85+
'empty' => "Please check I'm human(hcaptcha).",
86+
'unable_to_connect_api' => 'It is not possible to connect to hcaptcha services at this time. The Internet may be down or hcaptcha servers may be down. Try again in a few minutes.',
87+
'attack' => 'Avoid manipulating ReCaptcha form(I am not a robot).',
88+
// hCaptcha errors Api responses
89+
'missing-input-secret' => 'The hcaptcha secret parameter is missing.',
90+
'invalid_input_secret' => 'The hcaptcha secret parameter is invalid or malformed.',
91+
'missing_input_response' => 'The hcaptcha response parameter is missing.',
92+
'invalid_input_response' => 'The hcaptcha response parameter is invalid or malformed.',
93+
'bad_request' => 'The hcaptcha request is invalid or malformed.',
94+
'invalid_or_already_seen_response' => 'The response parameter has already been checked, or has another issue.',
95+
'not_using_dummy_passcode' => 'You have used a testing sitekey but have not used its matching secret.',
96+
'sitekey_secret_mismatch' => 'The sitekey is not registered with the provided secret.',
97+
],
98+
// filde name for print $this->validation->setRule('h-captcha-response', lang('MultiCaptchaCILang.hCaptcha.h-captcha-response'), 'required|hcaptcha');
99+
//if required use filde name set
100+
'h-captcha-response' => "I am human(hcaptcha)",
101+
],
81102

82103
];

CIMultiCaptcha/Language/fa/MultiCaptchaCILang.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* @author Pooya Parsa Dadashi
1010
* @link https://datamweb.ir
1111
* @github_link https://github.com/datamweb/CodeIgniter-Multi-Captcha
12-
* @since Version 1.0.0-pre-alpha
13-
* @datepublic 2022-02-19 | 1400/11/30
12+
* @since Version 1.0.1-pre-alpha
13+
* @datepublic 2022-02-23 | 1400/12/04
1414
*
1515
*/
1616

@@ -78,5 +78,26 @@
7878
//if required use filde name set
7979
'g-recaptcha-response' => 'من ربات نیستم گوگل',
8080
],
81+
// Custom Validation language for hCaptcha
82+
'hCaptcha'=> [
83+
'errors' => [
84+
'unknown' => 'سیستم به دلایلی شما را ربات تشخیص داد،مجدد تلاش کنید.',
85+
'empty' => 'لطفا،تیک من انسان هستم را بزنید.',
86+
'unable_to_connect_api' => 'در این دقایق امکان برقرای ارتباط با سرویس گوگل وجود ندارد.ممکن است اینترنت اختلال و یا سرورهای اچ کپچا از دسترس خارج باشند.',
87+
'attack' => 'از دستکاری فرم من ربات نیستم پرهیز کنید.',
88+
// hCaptcha errors Api responses
89+
'missing-input-secret' => 'پارامتر کلید مخفی hcaptcha سایت شما فراموش شده است',
90+
'invalid_input_secret' => 'کلید خصوصی گوگل اشتباه می باشد.از فایل کانفینگ کلید خصوصی hcaptcha را تنظیم کنید.',
91+
'missing_input_response' => 'پارامتر پاسخ کاربر به وب سرویس hcaptcha ارسال نشده است،لطفا از دستکاری فایلهای اصلی اجتناب کنید.واز فایل اصلی کتابخانه استفاده کنید.',
92+
'invalid_input_response' => 'پاسخ شما اشتباه تشخیص داده شد',
93+
'bad_request' => 'درخواست نا معتبر!',
94+
'invalid_or_already_seen_response' => 'پارامتر پاسخ قبلاً بررسی شده است یا مشکل دیگری دارد.',
95+
'not_using_dummy_passcode' => 'شما از یک کلیدسایت آزمایشی استفاده کرده اید اما از کلید مخفی مربوط به آن استفاده نکرده اید.',
96+
'sitekey_secret_mismatch' => ' کلید سایت با کلید مخفی ارائه شده ثبت نشده است.',
97+
],
98+
// filde name for print $this->validation->setRule('h-captcha-response', lang('MultiCaptchaCILang.hCaptcha.h-captcha-response'), 'required|hcaptcha');
99+
//if required use filde name set
100+
'h-captcha-response' => "من ربات نیستم(hcaptcha)",
101+
],
81102

82103
];

0 commit comments

Comments
 (0)