feat: 登录有效期24小时 + Cloudflare Turnstile 人机验证

- jwt_ttl 7200 → 86400 (24h)
- 管理登录/代理登录/代理注册 接入 Turnstile
- 前端 TurnstileWidget 组件, 未完成验证不可提交
- 密钥通过 env TURNSTILE_SITE_KEY/SECRET_KEY 配置
This commit is contained in:
root committed 2026-10-11 15:09:54 +08:00
1 parent 5b73d0921d
commit e90ade2ba0
10 files changed
+230 -12

No files matched your search

+22 -3
View File
@@ -6,6 +6,7 @@ use App\Core\Application;
use App\Core\Database;
use App\Core\Validator;
use App\Services\JwtService;
use App\Services\TurnstileService;
/**
* 认证控制器
@@ -52,6 +53,12 @@ class AuthController extends Controller
$this->error('请输入用户名或邮箱');
}
// Cloudflare Turnstile 人机验证
$turnstileToken = trim((string) ($input['turnstile_token'] ?? ''));
if (!TurnstileService::verify($turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
$this->error('人机验证失败,请完成验证后重试');
}
$db = Database::getInstance();
// 根据是否包含@选择查询方式
@@ -125,6 +132,12 @@ class AuthController extends Controller
$this->error('两次输入的密码不一致');
}
// Cloudflare Turnstile 人机验证
$turnstileToken = trim((string) ($input['turnstile_token'] ?? ''));
if (!TurnstileService::verify($turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
$this->error('人机验证失败,请完成验证后重试');
}
// 手机号格式验证
if (!preg_match('/^1[3-9]\d{9}$/', $input['phone'])) {
$this->error('手机号格式不正确');
@@ -255,12 +268,18 @@ class AuthController extends Controller
$this->error($validator->getFirstError());
}
$user = $this->getCurrentUser();
if (!passwordVerify($input['old_password'], $user['password'])) {
$db = Database::getInstance();
$user = $db->fetch(
"SELECT * FROM {$db->table('users')} WHERE id = ? AND deleted_at IS NULL",
[$this->getUserId()]
);
if (!$user) {
$this->error('用户不存在');
}
if (empty($user['password']) || !passwordVerify($input['old_password'], $user['password'])) {
$this->error('原密码错误');
}
$db = Database::getInstance();
$db->execute(
"UPDATE {$db->table('users')} SET password = ? WHERE id = ?",
[passwordHash($input['new_password']), $user['id']]