优化:注册与登录拦截处支持针对后台管理的永久禁用黑名单词汇采用“模糊匹配”(只要包含该词汇即拦截)

This commit is contained in:
2026-04-02 16:35:58 +08:00
parent 2786c8e7bf
commit 63292ab810

View File

@@ -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;
}
/**