Merge pull request #313 from elysias123/dev
Some checks failed
Docker Build and Publish / build (push) Has been cancelled

allow admin/staff unbind a user and better subscription domain names
This commit is contained in:
Xboard 2025-01-17 11:59:11 +08:00 committed by GitHub
commit 74d93691b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 5 deletions

View File

@ -12,11 +12,17 @@ class UnBind extends Telegram {
public function handle($message, $match = []) { public function handle($message, $match = []) {
if (!$message->is_private) return; if (!$message->is_private) return;
$user = User::where('telegram_id', $message->chat_id)->first(); if (!isset($message->args[0])) {
$telegramService = $this->telegramService; $user = User::where('telegram_id', $message->chat_id)->first();
if (!$user) { } else {
$telegramService->sendMessage($message->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown'); $chat = User::where('telegram_id', $message->chat_id)->first();
return; 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; $user->telegram_id = NULL;
if (!$user->save()) { if (!$user->save()) {

View File

@ -110,11 +110,20 @@ class Helper
public static function getSubscribeUrl(string $token, $subscribeUrl = null) 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); $path = route('client.subscribe', ['token' => $token], false);
if(!$subscribeUrl){ if(!$subscribeUrl){
$subscribeUrls = explode(',', admin_setting('subscribe_url')); $subscribeUrls = explode(',', admin_setting('subscribe_url'));
$subscribeUrl = \Arr::random($subscribeUrls); $subscribeUrl = \Arr::random($subscribeUrls);
$subscribeUrl = self::replaceByPattern($subscribeUrl); $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); return $subscribeUrl ? rtrim($subscribeUrl, '/') . $path : url($path);
} }