Register with hcaptcha
This commit is contained in:
parent
3adfcbd515
commit
9dc40eb62a
|
@ -82,6 +82,7 @@ if (!$cache_loaded) {
|
|||
|
||||
// ------------------------------------ Capshka settings ------------------------------------
|
||||
$cf['KU_DEFAULT_CAPTCHA_TYPE'] = 'default'; // ('default'|'hcaptcha'|'off') Default captcha type.
|
||||
$cf['KU_REGISTER_CAPTCHA_TYPE'] = 'default'; // ('default'|'hcaptcha') 2.0 registration captcha type.
|
||||
// hcaptcha credentials
|
||||
$cf['I0_HCAPTCHA_SITEKEY'] = 'your_site_key';
|
||||
$cf['I0_HCAPTCHA_SECRET'] = 'your_secret_key';
|
||||
|
|
|
@ -1246,15 +1246,31 @@ class Manage {
|
|||
</form>';
|
||||
}
|
||||
|
||||
public function CheckHcaptcha() {
|
||||
if ($_POST['h-captcha-response']) {
|
||||
$data = array(
|
||||
'secret' => I0_HCAPTCHA_SECRET,
|
||||
'response' => $_POST['h-captcha-response']
|
||||
);
|
||||
$verify = curl_init();
|
||||
curl_setopt($verify, CURLOPT_URL, "https://hcaptcha.com/siteverify");
|
||||
curl_setopt($verify, CURLOPT_POST, true);
|
||||
curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($verify);
|
||||
$responseData = json_decode($response);
|
||||
return ($responseData->success == true) ? 'ok' : 'incorrect';
|
||||
}
|
||||
return 'incorrect';
|
||||
}
|
||||
function sregister() {
|
||||
global $tc_db, $tpl_page;
|
||||
mb_internal_encoding("UTF-8");
|
||||
if(isset($_POST['username']) && isset($_POST['pass1']) && isset($_POST['pass2']) && $_POST['pass1'] == $_POST['pass2'] && $_POST['username'] != 'SERVER') {
|
||||
if(ctype_alnum($_POST['username']) && ctype_alnum($_POST['pass1'])) {
|
||||
if(strlen($_POST['username']) <= KU_20MAXLOGINPASS && strlen($_POST['pass1']) <= KU_20MAXLOGINPASS) {
|
||||
$submit_time = time();
|
||||
if($submit_time - $_SESSION['captchatime'] <= KU_CAPTCHALIFE) {
|
||||
if(!empty($_SESSION['security_code']) && $_SESSION['security_code'] == mb_strtoupper($_POST['captcha'])) {
|
||||
if (KU_REGISTER_CAPTCHA_TYPE === 'hcaptcha') {
|
||||
if($this->CheckHcaptcha() == 'ok') {
|
||||
$existing = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" .KU_DBPREFIX. "staff` WHERE `username` = " .$tc_db->qstr($_POST['username']));
|
||||
if(count($existing) == 0) {
|
||||
$salt = $this->CreateSalt();
|
||||
|
@ -1270,9 +1286,29 @@ class Manage {
|
|||
else {
|
||||
$tpl_page .= _gettext('Sorry, but you are not a human.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tpl_page .= _gettext('Captcha has expired.');
|
||||
} else {
|
||||
$submit_time = time();
|
||||
if($submit_time - $_SESSION['captchatime'] <= KU_CAPTCHALIFE) {
|
||||
if(!empty($_SESSION['security_code']) && $_SESSION['security_code'] == mb_strtoupper($_POST['captcha'])) {
|
||||
$existing = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" .KU_DBPREFIX. "staff` WHERE `username` = " .$tc_db->qstr($_POST['username']));
|
||||
if(count($existing) == 0) {
|
||||
$salt = $this->CreateSalt();
|
||||
$tc_db->Execute("INSERT HIGH_PRIORITY INTO `" .KU_DBPREFIX. "staff` ( `username` , `password` , `salt` , `type` , `addedon` ) VALUES (" .$tc_db->qstr($_POST['username']). " , '" .md5($_POST['pass1'] . $salt). "' , '" .$salt. "' , '3' , '" .time(). "' )");
|
||||
management_addlogentry('New user '.$_POST['username'].' has joined 2.0chan', 6, '', '', '2.0 service');
|
||||
$tpl_page = _gettext('Successfully registered new user. Now you can log in.');
|
||||
$this->LoginForm();
|
||||
}
|
||||
else {
|
||||
$tpl_page .= _gettext('A staff member with that ID already exists.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tpl_page .= _gettext('Sorry, but you are not a human.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tpl_page .= _gettext('Captcha has expired.');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue