-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f00f645
commit f4dc29b
Showing
4 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/** | ||
* Class Kohana_Recaptcha_Helper | ||
*/ | ||
class Kohana_Recaptcha_Helper | ||
{ | ||
const ARABIC = 'ar'; | ||
const AFRIKAANS = 'af'; | ||
const AMHARIC = 'am'; | ||
const ARMENIAN = 'hy'; | ||
const AZERBAIJANI = 'az'; | ||
const BASQUE = 'eu'; | ||
const BENGALI = 'bn'; | ||
const BULGARIAN = 'bg'; | ||
const CATALAN = 'ca'; | ||
const CHINESE_HK = 'zh-HK'; | ||
const CHINESE_SIMPLIFIED = 'zh-CN'; | ||
const CHINESE_TRADITIONAL = 'zh-TW'; | ||
const CROATIAN = 'hr'; | ||
const CZECH = 'cs'; | ||
const DANISH = 'da'; | ||
const DUTCH = 'nl'; | ||
const ENGLISH_UK = 'en-GB'; | ||
const ENGLISH_US = 'en'; | ||
const ESTONIAN = 'et'; | ||
const FILIPINO = 'fil'; | ||
const FINNISH = 'fi'; | ||
const FRENCH = 'fr'; | ||
const FRENCH_CANADIAN = 'fr-CA'; | ||
const GALICIAN = 'gl'; | ||
const GEORGIAN = 'ka'; | ||
const GERMAN = 'de'; | ||
const GERMAN_AUSTRIA = 'de-AT'; | ||
const GERMAN_SWITZERLAND = 'de-CH'; | ||
const GREEK = 'el'; | ||
const GUJURATI = 'gu'; | ||
const HEBREW = 'iw'; | ||
const HINDI = 'hi'; | ||
const HUNGARIAN = 'hu'; | ||
const ICELANDIC = 'is'; | ||
const INDONESIAN = 'id'; | ||
const ITALIAN = 'it'; | ||
const JAPANESE = 'ja'; | ||
const KANNADA = 'kn'; | ||
const KOREAN = 'ko'; | ||
const LAOTHIAN = 'lo'; | ||
const LATVIAN = 'lv'; | ||
const LITHUANIAN = 'lt'; | ||
const MALAY = 'ms'; | ||
const MALAYALAM = 'ml'; | ||
const MARATHI = 'mr'; | ||
const MONGOLIAN = 'mn'; | ||
const NORWEGIAN = 'no'; | ||
const PERSIAN = 'fa'; | ||
const POLISH = 'pl'; | ||
const PORTUGESE = 'pt'; | ||
const PORTUGESE_BRAZIL = 'pt-BR'; | ||
const PORTUGESE_PORTUGAL = 'pt-PT'; | ||
const ROMANIAN = 'ro'; | ||
const RUSSIAN = 'ru'; | ||
const SERBIAN = 'sr'; | ||
const SINHALESE = 'si'; | ||
const SLOVAK = 'sk'; | ||
const SLOVENIAN = 'sl'; | ||
const SPANISH = 'es'; | ||
const SPANISH_LATIN_AMERICA = 'es-419'; | ||
const SWAHILI = 'sw'; | ||
const SWEDISH = 'sv'; | ||
const TAMIL = 'ta'; | ||
const TELUGU = 'te'; | ||
const THAI = 'th'; | ||
const TURKISH = 'tr'; | ||
const UKRAINIAN = 'uk'; | ||
const URDU = 'ur'; | ||
const VIETNAMESE = 'vi'; | ||
const ZULU = 'zu'; | ||
|
||
/** | ||
* Get Api URL | ||
* @param String $lang | ||
* @param Recaptcha $recaptcha | ||
* @return String | ||
*/ | ||
public static function getApiUrl(String $lang = self::ENGLISH_US, Recaptcha $recaptcha) | ||
{ | ||
return 'https://www.google.com/recaptcha/api.js?' . http_build_query([ | ||
'hl' => $lang, | ||
'render' => $recaptcha::getSiteKey() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
/** | ||
* Class Recaptcha_Helper | ||
*/ | ||
class Recaptcha_Helper extends Kohana_Recaptcha_Helper | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Create PHP file: | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="<?= $recaptcha_helper::getApiUrl($recaptcha_helper::ENGLISH_US, $recaptcha) ?>"></script> | ||
<script> | ||
grecaptcha.ready(function () { | ||
grecaptcha.execute('<?=$recaptcha->getSiteKey()?>', {action: 'homepage'}).then(function (token) { | ||
let form = document.getElementById('firstForm'); | ||
var input = document.createElement('input'); | ||
input.type = 'hidden'; | ||
input.name = '<?=$recaptcha->getPublicKeyName()?>'; | ||
input.value = token; | ||
form.appendChild(input); | ||
}); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<form method="POST" id="firstForm"> | ||
<input type="text" name="name" value="test"/> | ||
<input type="submit" value="Send"/> | ||
</form> | ||
|
||
</body> | ||
</html> | ||
|
||
Kohana Controller: | ||
|
||
public function action_index() | ||
{ | ||
$this->template->recaptcha = new Recaptcha(); | ||
$this->template->recaptcha_helper = new Recaptcha_Helper(); | ||
|
||
if ($this->request->method() == Request::POST) | ||
{ | ||
$validation = Validation::factory($this->request->post()) | ||
//Action provided must be the same as in JS init | ||
->rule(Recaptcha::getPublicKeyName(), 'Recaptcha::recaptchaValid', [':value', 'homepage']); | ||
|
||
if ($validation->check()) | ||
{ | ||
echo 'no_errors'; | ||
} | ||
else | ||
{ | ||
var_dump($validation->errors()); | ||
} | ||
} | ||
} |