From 63292ab810993735ef324c85b6d97b6b9fee40b2 Mon Sep 17 00:00:00 2001 From: lkddi Date: Thu, 2 Apr 2026 16:35:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E4=B8=8E=E7=99=BB=E5=BD=95=E6=8B=A6=E6=88=AA=E5=A4=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=92=88=E5=AF=B9=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E6=B0=B8=E4=B9=85=E7=A6=81=E7=94=A8=E9=BB=91=E5=90=8D?= =?UTF-8?q?=E5=8D=95=E8=AF=8D=E6=B1=87=E9=87=87=E7=94=A8=E2=80=9C=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E5=8C=B9=E9=85=8D=E2=80=9D=EF=BC=88=E5=8F=AA=E8=A6=81?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E8=AF=A5=E8=AF=8D=E6=B1=87=E5=8D=B3=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/UsernameBlacklist.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/app/Models/UsernameBlacklist.php b/app/Models/UsernameBlacklist.php index 91c1c76..5ac0284 100644 --- a/app/Models/UsernameBlacklist.php +++ b/app/Models/UsernameBlacklist.php @@ -50,17 +50,24 @@ class UsernameBlacklist extends Model */ public static function isBlocked(string $username): bool { - return static::where('username', $username) - ->where(function ($q) { - // 永久禁用 - $q->where('type', 'permanent') - // 或:临时保留且尚未到期 - ->orWhere(function ($q2) { - $q2->where('type', 'temp') - ->where('reserved_until', '>', now()); - }); - }) + // 1. 检查是否存在精确匹配且未过期的“临时改名保留”名称 + $hasTemp = static::where('type', 'temp') + ->where('username', $username) + ->where('reserved_until', '>', now()) ->exists(); + + if ($hasTemp) { + return true; + } + + // 2. 检查永久禁用词,改为【模糊匹配】(只要新注册的名字中包含禁用词,拦截) + // 比如数据库禁用了 "admin",那么 "admin123" 也会触发拦截 + $hasPermanent = static::where('type', 'permanent') + ->where('username', '!=', '') + ->whereRaw('? LIKE CONCAT("%", username, "%")', [$username]) + ->exists(); + + return $hasPermanent; } /**