diff --git a/web/app/Controllers/AccountSecurityController.php b/web/app/Controllers/AccountSecurityController.php index ec8a0e86..5d1899a8 100644 --- a/web/app/Controllers/AccountSecurityController.php +++ b/web/app/Controllers/AccountSecurityController.php @@ -7,7 +7,6 @@ use App\Services\AccountSecurityService; use App\Services\AdminCsrf; use App\Services\Auth; use App\Services\Payment\RechargeMethodsService; -use App\Services\UserFeatureRestrictionService; use App\Services\UserProfileService; use App\Utils\Hash; @@ -186,14 +185,6 @@ class AccountSecurityController extends BaseController public function rechargeOptions($request, $response, $args) { $user = Auth::getUser(); - if (UserFeatureRestrictionService::isRechargeRestricted($user)) { - return $this->json($response, [ - 'ret' => 0, - 'msg' => UserFeatureRestrictionService::RECHARGE_MESSAGE, - 'methods' => [], - ], 503); - } - return $this->json($response, [ 'ret' => 1, 'methods' => RechargeMethodsService::forUser($user), diff --git a/web/app/Controllers/CloudApiController.php b/web/app/Controllers/CloudApiController.php index 5dc8df38..522e5d09 100644 --- a/web/app/Controllers/CloudApiController.php +++ b/web/app/Controllers/CloudApiController.php @@ -75,10 +75,9 @@ final class CloudApiController private function userIsoImportAllowed(array $actor, bool $throw = false): bool { $user = User::where('id', $actor['user_id'])->first(); - $allowed = $user !== null && (int) $user->enable === 1 - && (int) $user->restrict_balance_purchase !== 1; + $allowed = $user !== null && (int) $user->enable === 1; if (!$allowed && $throw) { - throw new CloudError('账户套餐购买及 ISO 上传服务已被管理员停用', 403); + throw new CloudError('账户不可用,无法导入 ISO', 403); } return $allowed; } @@ -1331,15 +1330,12 @@ final class CloudApiController CloudMoney::cents((string) $user->money) ); $balanceSufficient = CloudMoney::cents($balance) >= $priceCents; - $purchaseAllowed = (int) $user->restrict_balance_purchase !== 1; $enabled = $priceCents > 0; $canChange = ($options['can_change'] ?? false) === true - && $enabled && $purchaseAllowed && $balanceSufficient; + && $enabled && $balanceSufficient; $message = (string) ($options['message'] ?? ''); if (!$enabled) { $message = '管理员尚未启用付费更换 IP。'; - } elseif (!$purchaseAllowed) { - $message = '账户付费操作已被管理员停用。'; } elseif (!$balanceSufficient) { $message = '账户余额不足,请先充值。'; } diff --git a/web/app/Controllers/PaytaroController.php b/web/app/Controllers/PaytaroController.php index a0d3b00e..550ef992 100644 --- a/web/app/Controllers/PaytaroController.php +++ b/web/app/Controllers/PaytaroController.php @@ -8,16 +8,12 @@ use App\Models\PaytaroOrder; use App\Services\Auth; use App\Services\Config; use App\Services\Payment\PaytaroPaymentService; -use App\Services\UserFeatureRestrictionService; class PaytaroController extends BaseController { public function create($request, $response, $args) { $user = Auth::getUser(); - if (UserFeatureRestrictionService::isRechargeRestricted($user)) { - return $this->json($response, ['code' => -1, 'msg' => UserFeatureRestrictionService::RECHARGE_MESSAGE], 503); - } try { $order = (new PaytaroPaymentService())->createOrder( $user, diff --git a/web/app/Controllers/UsdtController.php b/web/app/Controllers/UsdtController.php index 909e662f..1bbc35d7 100644 --- a/web/app/Controllers/UsdtController.php +++ b/web/app/Controllers/UsdtController.php @@ -6,19 +6,12 @@ use App\Models\UsdtPaymentOrder; use App\Services\Auth; use App\Services\Payment\UsdtConfig; use App\Services\Payment\UsdtPaymentService; -use App\Services\UserFeatureRestrictionService; class UsdtController extends BaseController { public function create($request, $response, $args) { $user = Auth::getUser(); - if (UserFeatureRestrictionService::isRechargeRestricted($user)) { - return $this->json($response, [ - 'code' => -1, - 'msg' => UserFeatureRestrictionService::RECHARGE_MESSAGE, - ], 503); - } if (!UsdtConfig::canUserAccess($user)) { return $this->json($response, ['code' => -1, 'msg' => 'USDT 充值当前不可用'], 403); } diff --git a/web/app/Controllers/UserController.php b/web/app/Controllers/UserController.php index 57d2622f..1563e2dc 100644 --- a/web/app/Controllers/UserController.php +++ b/web/app/Controllers/UserController.php @@ -33,7 +33,6 @@ use App\Services\ReferralConfig; use App\Services\Payment\UsdtConfig; use App\Services\Payment\YipayConfig; use App\Services\Payment\PaytaroConfig; -use App\Services\UserFeatureRestrictionService; use App\Services\TicketAttachmentService; use App\Services\TicketReplyService; use App\Services\UserDrawerService; @@ -274,29 +273,21 @@ class UserController extends BaseController public function code($request, $response, $args) { - - $codes = null; - $transactionRecordsRestricted = UserFeatureRestrictionService::isTransactionRecordsRestricted($this->user); - if (!$transactionRecordsRestricted) { - $pageNum = 1; - if (isset($request->getQueryParams()["page"])) { - $pageNum = $request->getQueryParams()["page"]; - } - $codes = Code::where('type', '<>', '-2')->where('userid', '=', $this->user->id)->orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum); - $codes->setPath('/user/code'); + $pageNum = 1; + if (isset($request->getQueryParams()["page"])) { + $pageNum = $request->getQueryParams()["page"]; } + $codes = Code::where('type', '<>', '-2')->where('userid', '=', $this->user->id)->orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum); + $codes->setPath('/user/code'); $yipayConfig = YipayConfig::values(); $yipayMethods = YipayConfig::visibleMethods($this->user, $yipayConfig); $yipayAlipayVisible = in_array('alipay', $yipayMethods, true); - $rechargeRestricted = UserFeatureRestrictionService::isRechargeRestricted($this->user); return $this->view() ->assign('codes', $codes) ->assign('usdt_enabled', UsdtConfig::isUserVisible($this->user)) ->assign('paytaro_enabled', PaytaroConfig::isUserVisible($this->user)) ->assign('yipay_alipay_enabled', $yipayAlipayVisible) ->assign('yipay_wxpay_enabled', in_array('wxpay', $yipayMethods, true)) - ->assign('recharge_restricted', $rechargeRestricted) - ->assign('transaction_records_restricted', $transactionRecordsRestricted) ->assign("cdn", $this->cdn) ->assign("backup_cdn", $this->backup_cdn) ->display('user/paytaro.tpl'); @@ -449,7 +440,6 @@ class UserController extends BaseController public function invite($request, $response, $args) { $user = Auth::getUser(); - $inviteRestricted = UserFeatureRestrictionService::isInviteRestricted($user); $inviteEnabled = $user->canInvite(); $inviteCode = null; if ($inviteEnabled) { @@ -462,7 +452,7 @@ class UserController extends BaseController $referralValues[ReferralConfig::VALID_DAYS_KEY] ?? ReferralConfig::DEFAULT_VALID_DAYS ); - return $this->view()->assign('invite_link', $invite_link)->assign('invite_enabled', $inviteEnabled)->assign('invite_restricted', $inviteRestricted)->assign('has_invite_code', $inviteCode !== null)->assign('aff_method', $this->aff_method)->assign('referral_rate', number_format(ReferralConfig::rateFor($user), 2, '.', ''))->assign('referral_days', $referralDays)->assign("cdn", $this->cdn)->assign("backup_cdn", $this->backup_cdn)->display('user/invite.tpl'); + return $this->view()->assign('invite_link', $invite_link)->assign('invite_enabled', $inviteEnabled)->assign('has_invite_code', $inviteCode !== null)->assign('aff_method', $this->aff_method)->assign('referral_rate', number_format(ReferralConfig::rateFor($user), 2, '.', ''))->assign('referral_days', $referralDays)->assign("cdn", $this->cdn)->assign("backup_cdn", $this->backup_cdn)->display('user/invite.tpl'); } public function doAff($request, $response, $args) @@ -540,13 +530,6 @@ class UserController extends BaseController if ($csrf !== null) { return $csrf; } - if (UserFeatureRestrictionService::isInviteRestricted($this->user)) { - return $this->echoJson($response, [ - 'ret' => 0, - 'msg' => UserFeatureRestrictionService::INVITE_MESSAGE, - ]); - } - if (!$this->user->canInvite()) { return $this->echoJson($response, [ 'ret' => 0, @@ -622,10 +605,6 @@ class UserController extends BaseController public function ticket($request, $response, $args) { - if ($this->ticketAccessRestricted()) { - return $this->ticketPageRestrictedResponse($response); - } - $pageNum = 1; if (isset($request->getQueryParams()["page"])) { $pageNum = $request->getQueryParams()["page"]; @@ -645,19 +624,12 @@ class UserController extends BaseController public function ticket_create($request, $response, $args) { - if ($this->ticketAccessRestricted()) { - return $this->ticketPageRestrictedResponse($response); - } - return $this->view()->assign('instances', $this->ticketInstances()) ->display('user/ticket_create.tpl'); } public function ticket_add($request, $response, $args) { - if ($this->ticketAccessRestricted()) { - return $this->ticketActionRestrictedResponse($response); - } if (!AdminCsrf::verify($request)) { return $this->echoJson($response, ['ret' => 0, 'msg' => '请求已过期,请刷新页面后重试']); } @@ -720,9 +692,6 @@ class UserController extends BaseController public function ticket_update($request, $response, $args) { - if ($this->ticketAccessRestricted()) { - return $this->ticketActionRestrictedResponse($response); - } if (!AdminCsrf::verify($request)) { return $this->echoJson($response, ['ret' => 0, 'msg' => '请求已过期,请刷新页面后重试']); } @@ -767,10 +736,6 @@ class UserController extends BaseController public function ticket_view($request, $response, $args) { - if ($this->ticketAccessRestricted()) { - return $this->ticketPageRestrictedResponse($response); - } - $id = $args['id']; $ticket_main = Ticket::where("id", "=", $id)->where("rootid", "=", 0)->first(); if ($ticket_main == null || $ticket_main->userid != $this->user->id) { @@ -808,9 +773,6 @@ class UserController extends BaseController public function ticket_attachment($request, $response, $args) { - if ($this->ticketAccessRestricted()) { - return $response->withStatus(404); - } if (!$this->ticketAttachmentsAvailable()) { return $response->withStatus(404); } @@ -825,11 +787,6 @@ class UserController extends BaseController return $this->streamTicketAttachment($response, $attachment); } - private function ticketAccessRestricted() - { - return UserFeatureRestrictionService::isTicketRestricted($this->user); - } - private function notifyTicketAdmins($event, $ticket, $content) { foreach (User::where('is_admin', 1)->get() as $admin) { @@ -930,19 +887,6 @@ class UserController extends BaseController } } - private function ticketPageRestrictedResponse($response) - { - return $response->withStatus(302)->withHeader('Location', '/user'); - } - - private function ticketActionRestrictedResponse($response) - { - return $this->echoJson($response, [ - 'ret' => 0, - 'msg' => UserFeatureRestrictionService::TICKET_MESSAGE, - ]); - } - public function disable($request, $response, $args) { return $this->view()->display('user/disable.tpl'); @@ -964,13 +908,6 @@ class UserController extends BaseController $user = Auth::getUser(); - if (UserFeatureRestrictionService::isInviteRestricted($user)) { - return $this->echoJson($response, [ - 'ret' => 0, - 'msg' => UserFeatureRestrictionService::INVITE_MESSAGE, - ]); - } - if (!$user->canInvite()) { return $this->echoJson($response, [ 'ret' => 0, diff --git a/web/app/Controllers/YipayController.php b/web/app/Controllers/YipayController.php index 40d27389..7fc93162 100644 --- a/web/app/Controllers/YipayController.php +++ b/web/app/Controllers/YipayController.php @@ -8,19 +8,12 @@ use App\Models\YipayOrder; use App\Services\Auth; use App\Services\Config; use App\Services\Payment\YipayPaymentService; -use App\Services\UserFeatureRestrictionService; class YipayController extends BaseController { public function create($request, $response, $args) { $user = Auth::getUser(); - if (UserFeatureRestrictionService::isRechargeRestricted($user)) { - return $this->json($response, [ - 'code' => -1, - 'msg' => UserFeatureRestrictionService::RECHARGE_MESSAGE, - ], 503); - } try { $order = (new YipayPaymentService())->createOrder( $user, diff --git a/web/app/Models/User.php b/web/app/Models/User.php index cf52d72f..7293ea68 100644 --- a/web/app/Models/User.php +++ b/web/app/Models/User.php @@ -9,7 +9,6 @@ namespace App\Models; use App\Utils\Hash; use App\Models\InviteCode; use App\Services\ReferralService; -use App\Services\UserFeatureRestrictionService; use App\Services\UserDataDeletionService; class User extends Model @@ -23,13 +22,6 @@ class User extends Model protected $casts = [ "enable" => 'int', - 'restrict_recharge' => 'int', - 'restrict_balance_purchase' => 'int', - 'restrict_invite' => 'int', - 'restrict_ticket' => 'int', - 'restrict_transaction_records' => 'int', - 'restriction_updated_at' => 'int', - 'restriction_operator_id' => 'int', 'login_session_version' => 'int', 'is_admin' => 'boolean', ]; @@ -61,7 +53,7 @@ class User extends Model public function canInvite() { - return (int) $this->enable === 1 && !UserFeatureRestrictionService::isInviteRestricted($this); + return (int) $this->enable === 1; } public function isAdmin() diff --git a/web/app/Services/Cloud/CloudInvoiceDetailPageService.php b/web/app/Services/Cloud/CloudInvoiceDetailPageService.php index 89c11bd9..8be2a303 100644 --- a/web/app/Services/Cloud/CloudInvoiceDetailPageService.php +++ b/web/app/Services/Cloud/CloudInvoiceDetailPageService.php @@ -5,7 +5,6 @@ namespace App\Services\Cloud; use App\Models\CloudInvoice; use App\Models\User; use App\Services\AdminCsrf; -use App\Services\UserFeatureRestrictionService; /** * Owner-scoped invoice detail payload shared by the HTML first paint and API. @@ -41,8 +40,7 @@ final class CloudInvoiceDetailPageService 'invoice' => $detail, 'payment_methods' => ($detail['payable'] ?? false) ? CloudInvoicePaymentService::methods($user) : [], - 'balance_payment_allowed' => (int) $user->enable === 1 - && !UserFeatureRestrictionService::isBalancePurchaseRestricted($user), + 'balance_payment_allowed' => (int) $user->enable === 1, 'balance' => (string) $user->money, 'csrf_token' => AdminCsrf::token(), 'user_id' => (string) $user->id, diff --git a/web/app/Services/Cloud/CloudInvoicePaymentService.php b/web/app/Services/Cloud/CloudInvoicePaymentService.php index c8c73d66..fc2df5f4 100644 --- a/web/app/Services/Cloud/CloudInvoicePaymentService.php +++ b/web/app/Services/Cloud/CloudInvoicePaymentService.php @@ -16,7 +16,6 @@ use App\Services\Payment\UsdtConfig; use App\Services\Payment\UsdtPaymentService; use App\Services\Payment\YipayConfig; use App\Services\Payment\YipayPaymentService; -use App\Services\UserFeatureRestrictionService; final class CloudInvoicePaymentService { @@ -95,7 +94,7 @@ final class CloudInvoicePaymentService * Recheck the account at the final, row-locked provider-order boundary. * * The controller performs the same validation for a useful early error, - * but an administrator can change account restrictions before the payment + * but an administrator can disable the account before the payment * provider's transaction begins. Each provider calls this method after it * locks the user row so a disabled account cannot still receive a real * external payment order through that race window. @@ -105,20 +104,10 @@ final class CloudInvoicePaymentService if ((int) $user->enable !== 1) { throw new CloudError('账户不存在或不可用', 403); } - if (UserFeatureRestrictionService::isBalancePurchaseRestricted($user)) { - throw new CloudError(UserFeatureRestrictionService::PURCHASE_MESSAGE, 403); - } - if (UserFeatureRestrictionService::isRechargeRestricted($user)) { - throw new CloudError(UserFeatureRestrictionService::RECHARGE_MESSAGE, 403); - } } public static function methods(User $user): array { - if (UserFeatureRestrictionService::isRechargeRestricted($user) - || UserFeatureRestrictionService::isBalancePurchaseRestricted($user)) { - return []; - } $methods = []; foreach (YipayConfig::visibleMethods($user) as $method) { $methods[] = ['id' => 'yipay_' . $method, @@ -137,26 +126,12 @@ final class CloudInvoicePaymentService string $clientIp, string $userAgent): array { CloudInput::only($input, ['method', 'idempotency_key']); - if (UserFeatureRestrictionService::isBalancePurchaseRestricted($user)) { - throw new CloudError(UserFeatureRestrictionService::PURCHASE_MESSAGE, 403); - } - if (UserFeatureRestrictionService::isRechargeRestricted($user)) { - throw new CloudError(UserFeatureRestrictionService::RECHARGE_MESSAGE, 403); - } $validated = (new CloudInstance())->getConnection()->transaction( function () use ($invoice, $user) { $lockedUser = User::where('id', $user->id)->lockForUpdate()->first(); if ($lockedUser === null || (int) $lockedUser->enable !== 1) { return ['error' => '账户不存在或不可用', 'status' => 403]; } - if (UserFeatureRestrictionService::isBalancePurchaseRestricted($lockedUser)) { - return ['error' => UserFeatureRestrictionService::PURCHASE_MESSAGE, - 'status' => 403]; - } - if (UserFeatureRestrictionService::isRechargeRestricted($lockedUser)) { - return ['error' => UserFeatureRestrictionService::RECHARGE_MESSAGE, - 'status' => 403]; - } if ((string) ($invoice->purpose ?: 'renewal') === 'provision') { $current = CloudInvoice::where('id', $invoice->id) ->where('user_id', $user->id)->lockForUpdate()->first(); diff --git a/web/app/Services/Cloud/CloudInvoiceService.php b/web/app/Services/Cloud/CloudInvoiceService.php index 2d625e6b..2900265d 100644 --- a/web/app/Services/Cloud/CloudInvoiceService.php +++ b/web/app/Services/Cloud/CloudInvoiceService.php @@ -918,9 +918,6 @@ final class CloudInvoiceService if ($user === null || (int) $user->enable !== 1) { throw new CloudError('账户不存在或不可用', 403); } - if ((int) $user->restrict_balance_purchase === 1) { - throw new CloudError('账户套餐购买服务已被管理员停用', 403); - } $sourcePurpose = (string) ($source->purpose ?: 'renewal'); $instance = null; if ($sourcePurpose !== 'provision') { diff --git a/web/app/Services/Cloud/CloudJobService.php b/web/app/Services/Cloud/CloudJobService.php index a46d33f2..d52dc9e8 100644 --- a/web/app/Services/Cloud/CloudJobService.php +++ b/web/app/Services/Cloud/CloudJobService.php @@ -2471,9 +2471,6 @@ final class CloudJobService if ($billingUser === null || (int) $billingUser->enable !== 1) { throw new CloudError('账户不可用', 403); } - if ((int) $billingUser->restrict_balance_purchase === 1) { - throw new CloudError('账户付费操作已被管理员停用', 403); - } if ((int) $locked->user_id !== (int) $billingUser->id) { throw new CloudError('只能为自己持有的实例更换 IP', 403); } diff --git a/web/app/Services/Cloud/CloudOrderService.php b/web/app/Services/Cloud/CloudOrderService.php index 27e87dc5..2438acb4 100644 --- a/web/app/Services/Cloud/CloudOrderService.php +++ b/web/app/Services/Cloud/CloudOrderService.php @@ -45,9 +45,6 @@ final class CloudOrderService if ($user === null || (int) $user->enable !== 1) { throw new CloudError('账户不可用', 403); } - if ((int) $user->restrict_balance_purchase === 1) { - throw new CloudError('账户套餐购买服务已被管理员停用', 403); - } $existing = CloudOrder::where('user_id', $user->id)->where('idempotency_key', $idempotency)->first(); if ($existing !== null) { if (!hash_equals($existing->request_hash, $requestHash)) { diff --git a/web/app/Services/Cloud/CloudRenewalService.php b/web/app/Services/Cloud/CloudRenewalService.php index 193e4ed0..474d3ff7 100644 --- a/web/app/Services/Cloud/CloudRenewalService.php +++ b/web/app/Services/Cloud/CloudRenewalService.php @@ -28,9 +28,6 @@ final class CloudRenewalService if ($user === null || (int) $user->enable !== 1) { throw new CloudError('账户不可用', 403); } - if ((int) $user->restrict_balance_purchase === 1) { - throw new CloudError('账户套餐购买服务已被管理员停用', 403); - } $existing = CloudRenewal::where('user_id', $user->id) ->where('idempotency_key', $idempotency)->first(); if ($existing !== null) { diff --git a/web/app/Services/UserFeatureRestrictionService.php b/web/app/Services/UserFeatureRestrictionService.php deleted file mode 100644 index 1dba4961..00000000 --- a/web/app/Services/UserFeatureRestrictionService.php +++ /dev/null @@ -1,54 +0,0 @@ -restrict_recharge === 1; - } - - public static function isBalancePurchaseRestricted(User $user) - { - return (int) $user->restrict_balance_purchase === 1; - } - - public static function isInviteRestricted(User $user) - { - return (int) $user->restrict_invite === 1; - } - - public static function isTicketRestricted(User $user) - { - return (int) $user->restrict_ticket === 1; - } - - public static function isTransactionRecordsRestricted(User $user) - { - return (int) $user->restrict_transaction_records === 1; - } - - public static function hasManualRestrictions(User $user) - { - return in_array(true, self::status($user), true); - } - - public static function status(User $user) - { - return [ - 'recharge' => self::isRechargeRestricted($user), - 'balance_purchase' => self::isBalancePurchaseRestricted($user), - 'invite' => self::isInviteRestricted($user), - 'ticket' => self::isTicketRestricted($user), - 'transaction_records' => self::isTransactionRecordsRestricted($user), - ]; - } -} diff --git a/web/app/Services/UserRestrictionEnforcementService.php b/web/app/Services/UserRestrictionEnforcementService.php deleted file mode 100644 index a43b4daa..00000000 --- a/web/app/Services/UserRestrictionEnforcementService.php +++ /dev/null @@ -1,300 +0,0 @@ -is_admin) { - continue; - } - - $userId = (int) $user->id; - $email = strtolower(trim((string) $user->email)); - if ($userId > 0) { - $userIds[$userId] = $userId; - } - if (filter_var($email, FILTER_VALIDATE_EMAIL)) { - $emails[$email] = $email; - } - } - - if (empty($userIds) && empty($emails)) { - return self::emptyResult(false); - } - - $result = self::emptyResult(true); - try { - $result['emails_added'] = self::appendEmailsToBlacklist(array_values($emails)); - if (!empty($emails)) { - EmailVerify::whereIn('email', array_values($emails))->delete(); - } - } catch (\Throwable $exception) { - $result['database_error'] = true; - error_log('User restriction email blacklist update failed: ' . $exception->getMessage()); - } - - try { - if ($redis === null) { - $redis = new RedisClient(); - } - $redis->del(self::EMAIL_BLACKLIST_KEY); - $result['trusted_devices_cleared'] = self::clearTrustedLoginDevices(array_values($userIds), $redis); - } catch (\Throwable $exception) { - $result['redis_error'] = true; - error_log('User restriction trusted device cleanup failed: ' . $exception->getMessage()); - } - - return $result; - } - - public static function releaseUsers($users, ?RedisClient $redis = null) - { - $emails = []; - foreach ($users as $user) { - if (!$user instanceof User || (bool) $user->is_admin) { - continue; - } - - $email = strtolower(trim((string) $user->email)); - if (filter_var($email, FILTER_VALIDATE_EMAIL)) { - $emails[$email] = $email; - } - } - - if (empty($emails)) { - return self::emptyResult(false); - } - - $result = self::emptyResult(false); - try { - $result['emails_removed'] = self::deleteEmailsFromBlacklist(array_values($emails)); - } catch (\Throwable $exception) { - $result['database_error'] = true; - error_log('User restriction email blacklist release failed: ' . $exception->getMessage()); - } - - try { - if ($redis === null) { - $redis = new RedisClient(); - } - $redis->del(self::EMAIL_BLACKLIST_KEY); - } catch (\Throwable $exception) { - $result['redis_error'] = true; - error_log('User restriction email blacklist cache cleanup failed: ' . $exception->getMessage()); - } - - return $result; - } - - public static function mergeEmailBlacklist($raw, array $emails) - { - $existing = []; - foreach (preg_split('/\r\n|\r|\n|,|;/', (string) $raw) as $line) { - $rule = strtolower(trim((string) $line)); - if (strpos($rule, '#') !== false) { - $rule = trim(explode('#', $rule, 2)[0]); - } - if (filter_var($rule, FILTER_VALIDATE_EMAIL)) { - $existing[$rule] = true; - } - } - - $added = []; - foreach ($emails as $email) { - $email = strtolower(trim((string) $email)); - if (!filter_var($email, FILTER_VALIDATE_EMAIL) || isset($existing[$email])) { - continue; - } - $existing[$email] = true; - $added[] = $email; - } - - if (empty($added)) { - return ['value' => (string) $raw, 'added' => []]; - } - - $value = rtrim((string) $raw); - if ($value !== '') { - $value .= "\n"; - } - $value .= implode("\n", $added); - - return ['value' => $value, 'added' => $added]; - } - - public static function removeEmailsFromBlacklist($raw, array $emails) - { - $targets = []; - foreach ($emails as $email) { - $email = strtolower(trim((string) $email)); - if (filter_var($email, FILTER_VALIDATE_EMAIL)) { - $targets[$email] = true; - } - } - - if (empty($targets)) { - return ['value' => (string) $raw, 'removed' => []]; - } - - $kept = []; - $removed = []; - foreach (preg_split('/\r\n|\r|\n|,|;/', (string) $raw) as $entry) { - $entry = trim((string) $entry); - if ($entry === '') { - continue; - } - - $rule = strtolower($entry); - if (strpos($rule, '#') !== false) { - $rule = trim(explode('#', $rule, 2)[0]); - } - if (filter_var($rule, FILTER_VALIDATE_EMAIL) && isset($targets[$rule])) { - $removed[$rule] = $rule; - continue; - } - - $kept[] = $entry; - } - - if (empty($removed)) { - return ['value' => (string) $raw, 'removed' => []]; - } - - return [ - 'value' => implode("\n", $kept), - 'removed' => array_values($removed), - ]; - } - - private static function appendEmailsToBlacklist(array $emails) - { - if (empty($emails)) { - return 0; - } - - $connection = (new Configurations())->getConnection(); - return $connection->transaction(function () use ($emails) { - $configuration = Configurations::where('name', self::EMAIL_BLACKLIST_KEY) - ->lockForUpdate() - ->first(); - if ($configuration === null) { - $configuration = new Configurations(); - $configuration->name = self::EMAIL_BLACKLIST_KEY; - $configuration->value = ''; - } - - $merged = self::mergeEmailBlacklist((string) $configuration->value, $emails); - if (empty($merged['added'])) { - return 0; - } - - $configuration->value = $merged['value']; - $configuration->save(); - - return count($merged['added']); - }); - } - - private static function deleteEmailsFromBlacklist(array $emails) - { - if (empty($emails)) { - return 0; - } - - $connection = (new Configurations())->getConnection(); - return $connection->transaction(function () use ($emails) { - $configuration = Configurations::where('name', self::EMAIL_BLACKLIST_KEY) - ->lockForUpdate() - ->first(); - if ($configuration === null) { - return 0; - } - - $filtered = self::removeEmailsFromBlacklist((string) $configuration->value, $emails); - if (empty($filtered['removed'])) { - return 0; - } - - $configuration->value = $filtered['value']; - $configuration->save(); - - return count($filtered['removed']); - }); - } - - private static function clearTrustedLoginDevices(array $userIds, RedisClient $redis) - { - if (empty($userIds)) { - return 0; - } - - $wanted = array_fill_keys(array_map('intval', $userIds), true); - $client = $redis->getClient(); - $keys = []; - try { - $cursor = '0'; - do { - $result = $client->executeRaw([ - 'SCAN', - $cursor, - 'MATCH', - self::TRUSTED_LOGIN_DEVICE_PREFIX . '*', - 'COUNT', - '500', - ]); - if (!is_array($result) || count($result) < 2) { - break; - } - - $cursor = (string) $result[0]; - $batch = is_array($result[1]) ? $result[1] : []; - foreach ($batch as $key) { - if (preg_match('/^trusted_login_device:(\d+):/', (string) $key, $matches) - && isset($wanted[(int) $matches[1]])) { - $keys[(string) $key] = (string) $key; - } - } - } while ($cursor !== '0'); - } catch (\Throwable $exception) { - foreach ($userIds as $userId) { - try { - foreach ((array) $client->keys(self::TRUSTED_LOGIN_DEVICE_PREFIX . (int) $userId . ':*') as $key) { - $keys[(string) $key] = (string) $key; - } - } catch (\Throwable $innerException) { - continue; - } - } - } - - foreach ($keys as $key) { - $redis->del($key); - } - - return count($keys); - } - - private static function emptyResult($enforced) - { - return [ - 'enforced' => (bool) $enforced, - 'emails_added' => 0, - 'emails_removed' => 0, - 'trusted_devices_cleared' => 0, - 'database_error' => false, - 'redis_error' => false, - ]; - } -} diff --git a/web/app/Services/View.php b/web/app/Services/View.php index 33151e0a..6dc16ed5 100644 --- a/web/app/Services/View.php +++ b/web/app/Services/View.php @@ -46,16 +46,6 @@ class View 'admin_display_user_name', is_object($user) && isset($user->user_name) ? AdminDataMasker::account($user->user_name) : '' ); - $smarty->assign( - 'ticket_navigation_enabled', - $user === null || !$user->isLogin || !UserFeatureRestrictionService::isTicketRestricted($user) - ); - $smarty->assign( - 'transaction_records_visible', - $user === null || !$user->isLogin || !UserFeatureRestrictionService::isTransactionRecordsRestricted($user) - ); - // Navigation is rendered server-side, but the API repeats this check. - // Hiding this link is never treated as the authorisation boundary. $smarty->assign('user_iso_enabled', is_object($user) && $user->isLogin ? CloudUserIsoFeature::enabled() : false); return $smarty; diff --git a/web/resources/views/venix/user/invite.tpl b/web/resources/views/venix/user/invite.tpl index 3f6911eb..b11b0048 100644 --- a/web/resources/views/venix/user/invite.tpl +++ b/web/resources/views/venix/user/invite.tpl @@ -13,8 +13,7 @@
好友通过此链接注册后,{$referral_days} 天内符合条件的充值将计入返利。
推广服务暂时无法使用
- {elseif !$invite_enabled}推广功能暂不可用
+ {if !$invite_enabled}推广功能暂不可用
{elseif $invite_link != ''}{$invite_link|escape:'html'}
{else}尚未生成推广链接{/if}
此处仅使用合成数据,公告首屏使用安全摘要并在打开后静默校验。
用于检查打开公告前后页面滚动位置。