feat: 人机验证可开关 + 登录注册入口白名单
- 系统设置新增「人机验证」页: 总开关 + 按入口勾选 - 客户端 verify/activate/check-update 永不校验 Turnstile - 公开 GET /api/public/turnstile-config 供登录页按需展示组件
This commit is contained in:
1 parent
217c083544
commit
7c85ecdd2d
9 files changed
+262
-21
No files matched your search
@@ -53,9 +53,10 @@ class AuthController extends Controller
|
||||
$this->error('请输入用户名或邮箱');
|
||||
}
|
||||
|
||||
// Cloudflare Turnstile 人机验证
|
||||
// Cloudflare Turnstile(按系统配置开关与入口白名单)
|
||||
$portalKey = $portal === 'agent' ? 'agent_login' : 'admin_login';
|
||||
$turnstileToken = trim((string) ($input['turnstile_token'] ?? ''));
|
||||
if (!TurnstileService::verify($turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
|
||||
if (!TurnstileService::verifyFor($portalKey, $turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
|
||||
$this->error('人机验证失败,请完成验证后重试');
|
||||
}
|
||||
|
||||
@@ -132,9 +133,9 @@ class AuthController extends Controller
|
||||
$this->error('两次输入的密码不一致');
|
||||
}
|
||||
|
||||
// Cloudflare Turnstile 人机验证
|
||||
// Cloudflare Turnstile(按系统配置开关与入口白名单)
|
||||
$turnstileToken = trim((string) ($input['turnstile_token'] ?? ''));
|
||||
if (!TurnstileService::verify($turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
|
||||
if (!TurnstileService::verifyFor('agent_register', $turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
|
||||
$this->error('人机验证失败,请完成验证后重试');
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Core\Database;
|
||||
use App\Core\Validator;
|
||||
use App\Services\InstallationService;
|
||||
use App\Services\VersionService;
|
||||
use App\Services\TurnstileService;
|
||||
|
||||
/**
|
||||
* 公开接口控制器
|
||||
@@ -746,6 +747,21 @@ class PublicController extends Controller
|
||||
$this->success(['valid' => false, 'message' => '卡密状态异常'], 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 人机验证公开配置(前端登录页判断是否展示组件)
|
||||
* GET /api/public/turnstile-config
|
||||
* 注意:客户端 verify/activate/check-update 等接口从不校验 Turnstile
|
||||
*/
|
||||
public function turnstileConfig(): void
|
||||
{
|
||||
$c = \App\Services\TurnstileService::config();
|
||||
$this->success([
|
||||
'enabled' => $c['enabled'] === 1 && $c['site_key'] !== '',
|
||||
'site_key' => $c['site_key'],
|
||||
'endpoints' => $c['endpoints'],
|
||||
], 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公告列表(公开/客户端)
|
||||
* GET /api/public/announcements?target=client&project_id=1&limit=10
|
||||
|
||||
Reference in new issue
Block a user