From e2262f14355c7d0f15f9b2d9a82265eeb83801d2 Mon Sep 17 00:00:00 2001 From: Elysia <118418714+elysias123@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:31:51 +0800 Subject: [PATCH 1/2] feat: allow admin/staff unbind a user --- app/Plugins/Telegram/Commands/UnBind.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Plugins/Telegram/Commands/UnBind.php b/app/Plugins/Telegram/Commands/UnBind.php index ebd9325..67fd022 100644 --- a/app/Plugins/Telegram/Commands/UnBind.php +++ b/app/Plugins/Telegram/Commands/UnBind.php @@ -12,11 +12,17 @@ class UnBind extends Telegram { public function handle($message, $match = []) { if (!$message->is_private) return; - $user = User::where('telegram_id', $message->chat_id)->first(); - $telegramService = $this->telegramService; - if (!$user) { - $telegramService->sendMessage($message->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown'); - return; + if (!isset($message->args[0])) { + $user = User::where('telegram_id', $message->chat_id)->first(); + } else { + $chat = User::where('telegram_id', $message->chat_id)->first(); + if (!$chat) return; + if (!($chat->is_admin || $chat->is_staff)) return; + if (strpos($message->args[0], '@') !== true) { + $user = User::where('email', $message->args[0])->first(); + } else { + $user = User::where('telegram_id', $message->args[0])->first(); + } } $user->telegram_id = NULL; if (!$user->save()) { From a550fd1436e5213c792fd69f97420bb4f6446ec1 Mon Sep 17 00:00:00 2001 From: Elysia Date: Tue, 14 Jan 2025 13:54:26 +0800 Subject: [PATCH 2/2] feat: Replace with a random string when the subscription domain contains *&Replace with the user uuid when the subscription domain contains {uuid} --- app/Utils/Helper.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Utils/Helper.php b/app/Utils/Helper.php index 341df4e..c88272a 100644 --- a/app/Utils/Helper.php +++ b/app/Utils/Helper.php @@ -110,11 +110,20 @@ class Helper public static function getSubscribeUrl(string $token, $subscribeUrl = null) { + $strs = 'QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm'; + $randstr = substr(str_shuffle($strs), 0, rand(4,8)); + $path = route('client.subscribe', ['token' => $token], false); if(!$subscribeUrl){ $subscribeUrls = explode(',', admin_setting('subscribe_url')); $subscribeUrl = \Arr::random($subscribeUrls); $subscribeUrl = self::replaceByPattern($subscribeUrl); + if (strpos($subscribeUrl, "*") !== false) { + $subscribeUrl = str_replace("*", $randstr, $subscribeUrl); + } elseif (strpos($subscribeUrl, '{uuid}') !== false) { + $user = User::where('token', $token)->first(); + $subscribeUrl = str_replace('{uuid}', $user->uuid, $subscribeUrl); + } } return $subscribeUrl ? rtrim($subscribeUrl, '/') . $path : url($path); }