Skip to content

Commit

Permalink
refactor: backend captcha logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AutisticShark committed Oct 19, 2022
1 parent bc507b5 commit cec8ba5
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 702 deletions.
1 change: 0 additions & 1 deletion app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
$this->post('/send', App\Controllers\AuthController::class . ':sendVerify');
$this->get('/logout', App\Controllers\AuthController::class . ':logout');
$this->get('/telegram_oauth', App\Controllers\AuthController::class . ':telegramOauth');
$this->get('/login_getCaptcha', App\Controllers\AuthController::class . ':getCaptcha');
})->add(new Guest());

// Password
Expand Down
6 changes: 0 additions & 6 deletions config/.config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,6 @@
#捐赠
$_ENV['enable_donate'] = true; //是否显示用户捐赠(所有收入将被公开)

#iOS账户显示
$_ENV['display_ios_class'] = -1; //至少等级为多少的用户可以看见,小于0时关闭此功能
$_ENV['display_ios_topup'] = 0; //满足等级要求后,累计充值高于多少的用户可以看见
$_ENV['ios_account'] = ''; //iOS账户
$_ENV['ios_password'] = ''; //iOS密码

//节点检测-----------------------------------------------------------------------------------------------
#GFW检测,请通过crontab进行【开启/关闭】
$_ENV['detect_gfw_interval'] = 3600; //检测间隔,单位:秒,低于推荐值会爆炸
Expand Down
1 change: 0 additions & 1 deletion phpinsights.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@

'exclude' => [
'storage',
'src/Utils/GeetestLib.php',
],
];
4 changes: 0 additions & 4 deletions public/theme/material/css/auth.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ a.boardtop-left:hover {
position: relative;
}

.labelgeetest {
justify-content: center;
}

.auth-top a div:last-of-type {
font-size: 13px;
}
Expand Down
17 changes: 0 additions & 17 deletions public/theme/material/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -6833,23 +6833,6 @@ html.no-touchevents .tile:hover .tile-action {
background: white;
}

/* geetest */

#embed-captcha .geetest_holder.geetest_wind,
#popup-captcha .geetest_holder.geetest_wind {
width: 100% !important;
min-width: unset;
}

#embed-captcha .geetest_holder.geetest_wind .geetest_radar_btn,
#popup-captcha .geetest_holder.geetest_wind .geetest_radar_btn {
background: white;
background-image: unset;
box-shadow: 2px 3px 5px #e0e0e0;
border-radius: 5px;
min-width: unset;
}

.tgme_widget_login.large button.tgme_widget_login_button {
max-width: 80%;
}
Expand Down
6 changes: 0 additions & 6 deletions public/theme/material/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,6 @@ select {
min-height: 44px;
}

#embed-captcha-reg .geetest_btn {
margin-left: auto;
margin-right: auto;
width: 87%;
}

.auth-tg {
margin-top: 2rem;
}
Expand Down
50 changes: 1 addition & 49 deletions resources/views/material/auth/login.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@
</div>
</div>

{if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'geetest'}
<div class="form-group-label labelgeetest auth-row">
<div id="embed-captcha"></div>
</div>
{/if}
{if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
<div class="form-group-label auth-row">
<div class="row">
<div align="center" class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
<div align="center" class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
</div>
</div>
{/if}
Expand Down Expand Up @@ -104,14 +99,6 @@
<script>
$(document).ready(function () {
function login() {
{if $geetest_html != null}
if (typeof validate === 'undefined' || !validate) {
$("#result").modal();
$$.getElementById('msg').innerHTML = '请滑动验证码来完成验证';
return;
}
{/if}
document.getElementById("login").disabled = true;
$.ajax({
Expand All @@ -122,11 +109,6 @@
{if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
turnstile: turnstile.getResponse(),
{/if}
{if $geetest_html != null}
geetest_challenge: validate.geetest_challenge,
geetest_validate: validate.geetest_validate,
geetest_seccode: validate.geetest_seccode,
{/if}
code: $$getValue('code'),
email: $$getValue('email'),
passwd: $$getValue('passwd'),
Expand All @@ -141,9 +123,6 @@
$("#result").modal();
$$.getElementById('msg').innerHTML = data.msg;
document.getElementById("login").disabled = false;
{if $geetest_html != null}
captcha.refresh();
{/if}
}
},
error: (jqXHR) => {
Expand All @@ -153,9 +132,6 @@
jqXHR.status
}`;
document.getElementById("login").disabled = false;
{if $geetest_html != null}
captcha.refresh();
{/if}
}
});
}
Expand All @@ -179,30 +155,6 @@
})
</script>

{if $geetest_html != null}
<script>
var handlerEmbed = function (captchaObj) {
// 将验证码加到id为captcha的元素里
captchaObj.onSuccess(function () {
validate = captchaObj.getValidate();
});
captchaObj.appendTo("#embed-captcha");
captcha = captchaObj;
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
};
initGeetest({
gt: "{$geetest_html->gt}",
challenge: "{$geetest_html->challenge}",
product: "embed", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline: {if $geetest_html->success}0{else}1{/if} // 表示用户后台检测极验服务器是否宕机,与SDK配合,用户一般不需要关注
}, handlerEmbed);
</script>
{/if}

{if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?compat=recaptcha" async defer></script>
{/if}
65 changes: 1 addition & 64 deletions resources/views/material/auth/register.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,10 @@
</div>
</div>
{/if}
{if $geetest_html != null}
<div class="rowtocol">
<div class="form-group form-group-label">
<div id="embed-captcha"></div>
</div>
</div>
{/if}
{if $config['enable_reg_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
<div class="form-group form-group-label">
<div class="row">
<div align="center" class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
<div align="center" class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
</div>
</div>
{/if}
Expand Down Expand Up @@ -263,11 +256,6 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
{if $config['enable_reg_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
turnstile: turnstile.getResponse(),
{/if}
{if $geetest_html != null}
geetest_challenge: validate.geetest_challenge,
geetest_validate: validate.geetest_validate,
geetest_seccode: validate.geetest_seccode,
{/if}
{if $config['enable_reg_im'] == true}
im_value: $$getValue('im_value'),
im_type: $$getValue('im_type'),
Expand All @@ -292,9 +280,6 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
setCookie('code', '', 0);
$("#code").val(getCookie('code'));
document.getElementById("tos").disabled = false;
{if $geetest_html != null}
captcha.refresh();
{/if}
}
},
error: (jqXHR) => {
Expand All @@ -304,9 +289,6 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
jqXHR.status
}`;
document.getElementById("tos").disabled = false;
{if $geetest_html != null}
captcha.refresh();
{/if}
}
});
}
Expand All @@ -317,32 +299,11 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
}
});
{if $geetest_html != null}
$('div.modal').on('shown.bs.modal', function () {
$("div.gt_slider_knob").hide();
});
$('div.modal').on('hidden.bs.modal', function () {
$("div.gt_slider_knob").show();
});
{/if}
$("#reg").click(function () {
register();
});
$("#tos").click(function () {
{if $geetest_html != null}
if (typeof validate === 'undefined' || !validate) {
$("#result").modal();
$$.getElementById('msg').innerHTML = '请滑动验证码来完成验证'
return;
}
{/if}
$("#tos_modal").modal();
});
})
Expand Down Expand Up @@ -402,30 +363,6 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
</script>
{/if}

{if $geetest_html != null}
<script>
var handlerEmbed = function (captchaObj) {
// 将验证码加到id为captcha的元素里
captchaObj.onSuccess(function () {
validate = captchaObj.getValidate();
});
captchaObj.appendTo("#embed-captcha");
captcha = captchaObj;
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
};
initGeetest({
gt: "{$geetest_html->gt}",
challenge: "{$geetest_html->challenge}",
product: "embed", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline: {if $geetest_html->success}0{else}1{/if} // 表示用户后台检测极验服务器是否宕机,与SDK配合,用户一般不需要关注
}, handlerEmbed);
</script>
{/if}

{if $config['enable_reg_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?compat=recaptcha" async defer></script>
{/if}
Expand Down
3 changes: 0 additions & 3 deletions resources/views/material/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

<!-- js -->
<script src="https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js"></script>
{if isset($geetest_html)}
<script src="//static.geetest.com/static/tools/gt.js"></script>
{/if}
<script src="/theme/material/js/base.min.js"></script>
<script src="/theme/material/js/project.min.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion resources/views/material/password/reset.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{if $config['enable_reset_password_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
<div class="form-group-label auth-row">
<div class="row">
<div align="center" class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
<div align="center" class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
</div>
</div>
{/if}
Expand Down
3 changes: 0 additions & 3 deletions resources/views/material/user/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
</footer>

<!-- js -->
{if isset($geetest_html)}
<script src="//static.geetest.com/static/tools/gt.js"></script>
{/if}
<script src="/theme/material/js/base.min.js"></script>
<script src="/theme/material/js/project.min.js"></script>
<script src="//cdn.staticfile.org/clipboard.js/2.0.11/clipboard.min.js"></script>
Expand Down
Loading

0 comments on commit cec8ba5

Please sign in to comment.