Browse Source

refactor: clean up models & merge telegram

Cat 2 years ago
parent
commit
74c4c6d6de

+ 1 - 1
src/Controllers/LinkController.php

@@ -44,7 +44,7 @@ final class LinkController extends BaseController
             ]);
         }
 
-        $user = $Elink->getUser();
+        $user = $Elink->user();
         if ($user === null) {
             return $response->withJson([
                 'ret' => 0,

+ 13 - 12
src/Controllers/PasswordController.php

@@ -12,6 +12,7 @@ use App\Services\Password;
 use App\Utils\Hash;
 use App\Utils\ResponseHelper;
 use Exception;
+use Psr\Http\Client\ClientExceptionInterface;
 use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Response;
 use Slim\Http\ServerRequest;
@@ -55,15 +56,14 @@ final class PasswordController extends BaseController
 
         $email = strtolower($request->getParam('email'));
         $user = User::where('email', $email)->first();
+        $msg = '如果你的账户存在于我们的数据库中,那么重置密码的链接将会发送到你账户所对应的邮箱。';
 
-        if ($user === null) {
-            $msg = '如果你的账户存在于我们的数据库中,那么重置密码的链接将会发送到你账户所对应的邮箱。';
-        }
-
-        if (Password::sendResetEmail($email)) {
-            $msg = '如果你的账户存在于我们的数据库中,那么重置密码的链接将会发送到你账户所对应的邮箱。';
-        } else {
-            $msg = '邮件发送失败,请联系网站管理员。';
+        if ($user !== null) {
+            try {
+                Password::sendResetEmail($email);
+            } catch (ClientExceptionInterface $e) {
+                $msg = '邮件发送失败,请联系网站管理员。';
+            }
         }
 
         return ResponseHelper::successfully($response, $msg);
@@ -74,7 +74,8 @@ final class PasswordController extends BaseController
      */
     public function token(ServerRequest $request, Response $response, array $args)
     {
-        $token = PasswordReset::where('token', $args['token'])->where('expire_time', '>', time())->orderBy('id', 'desc')->first();
+        $token = PasswordReset::where('token', $args['token'])
+            ->where('expire_time', '>', time())->orderBy('id', 'desc')->first();
         if ($token === null) {
             return $response->withStatus(302)->withHeader('Location', '/password/reset');
         }
@@ -99,12 +100,13 @@ final class PasswordController extends BaseController
         }
 
         /** @var PasswordReset $token */
-        $token = PasswordReset::where('token', $tokenStr)->where('expire_time', '>', time())->orderBy('id', 'desc')->first();
+        $token = PasswordReset::where('token', $tokenStr)
+            ->where('expire_time', '>', time())->orderBy('id', 'desc')->first();
         if ($token === null) {
             return ResponseHelper::error($response, '链接已经失效,请重新获取');
         }
 
-        $user = $token->getUser();
+        $user = $token->user();
         if ($user === null) {
             return ResponseHelper::error($response, '链接已经失效,请重新获取');
         }
@@ -112,7 +114,6 @@ final class PasswordController extends BaseController
         // reset password
         $hashPassword = Hash::passwordHash($password);
         $user->pass = $hashPassword;
-        $user->ga_enable = 0;
 
         if (! $user->save()) {
             return ResponseHelper::error($response, '重置失败,请重试');

+ 1 - 1
src/Controllers/SubController.php

@@ -39,7 +39,7 @@ final class SubController extends BaseController
             ]);
         }
 
-        $user = $sub_token->getUser();
+        $user = $sub_token->user();
         if ($user === null) {
             return $response->withJson([
                 'ret' => 0,

+ 2 - 2
src/Controllers/UserController.php

@@ -22,7 +22,7 @@ use App\Services\MFA;
 use App\Utils\Cookie;
 use App\Utils\Hash;
 use App\Utils\ResponseHelper;
-use App\Utils\TelegramSessionManager;
+use App\Utils\Telegram;
 use App\Utils\Tools;
 use Exception;
 use Psr\Http\Message\ResponseInterface;
@@ -203,7 +203,7 @@ final class UserController extends BaseController
     public function edit(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
         $themes = Tools::getDir(BASE_PATH . '/resources/views');
-        $bind_token = TelegramSessionManager::addBindSession($this->user);
+        $bind_token = Telegram::addBindSession($this->user);
         $methods = Config::getSupportParam('method');
         $gaurl = MFA::getGAurl($this->user);
 

+ 0 - 98
src/Models/Bought.php

@@ -22,44 +22,8 @@ use function time;
 final class Bought extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'bought';
 
-    /**
-     * [静态方法] 删除不存在的用户的记录
-     */
-    public static function userIsNull(Bought $Bought): void
-    {
-        self::where('userid', $Bought->userid)->delete();
-    }
-
-    /**
-     * [静态方法] 删除不存在的商品的记录
-     */
-    public static function shopIsNull(Bought $Bought): void
-    {
-        self::where('shopid', $Bought->shopid)->delete();
-    }
-
-    /**
-     * 自动续费时间
-     */
-    public function renew(): string
-    {
-        if ($this->renew === 0) {
-            return '不自动续费';
-        }
-        return date('Y-m-d H:i:s', $this->renew) . ' 时续费';
-    }
-
-    /**
-     * 购买日期
-     */
-    public function datetime(): string
-    {
-        return date('Y-m-d H:i:s', (int) $this->datetime);
-    }
-
     /**
      * 购买用户
      */
@@ -68,17 +32,6 @@ final class Bought extends Model
         return User::find($this->userid);
     }
 
-    /**
-     * 购买用户名
-     */
-    public function userName(): string
-    {
-        if ($this->user() === null) {
-            return '用户已不存在';
-        }
-        return $this->user()->user_name;
-    }
-
     /**
      * 商品
      */
@@ -87,28 +40,6 @@ final class Bought extends Model
         return Shop::find($this->shopid);
     }
 
-    /**
-     * 商品内容
-     */
-    public function content(): string
-    {
-        if ($this->shop() === null) {
-            return '商品已不存在';
-        }
-        return $this->shop()->content();
-    }
-
-    /**
-     * 流量是否自动重置
-     */
-    public function autoResetBandwidthString(): string
-    {
-        if ($this->shop() === null) {
-            return '商品已不存在';
-        }
-        return $this->shop()->auto_reset_bandwidth === 0 ? '不自动重置' : '自动重置';
-    }
-
     /*
      * 套餐已使用的天数
      */
@@ -128,33 +59,4 @@ final class Bought extends Model
         }
         return false;
     }
-
-    /*
-     * 下一次流量重置时间
-     */
-    public function resetTime($unix = false): float|int|string
-    {
-        $shop = $this->shop();
-        if ($shop->useLoop()) {
-            $day = 24 * 60 * 60;
-            $resetIndex = 1 + (int) ((time() - $this->datetime - $day) / ($shop->reset() * $day));
-            $restTime = $resetIndex * $shop->reset() * $day + (int) $this->datetime;
-            $time = time() + ($day * 86400);
-            return ! $unix ? date('Y-m-d', strtotime('+1 day', strtotime(date('Y-m-d', (int) $restTime)))) : $time;
-        }
-        return ! $unix ? '-' : 0;
-    }
-
-    /*
-     * 过期时间
-     */
-    public function expTime($unix = false): float|int|string
-    {
-        $shop = $this->shop();
-        if ($shop->useLoop()) {
-            $time = (int) $this->datetime + ($shop->resetExp() * 86400);
-            return ! $unix ? date('Y-m-d H:i:s', (int) $time) : $time;
-        }
-        return ! $unix ? '-' : 0;
-    }
 }

+ 0 - 63
src/Models/Code.php

@@ -10,7 +10,6 @@ namespace App\Models;
 final class Code extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'code';
 
     /**
@@ -20,66 +19,4 @@ final class Code extends Model
     {
         return User::find($this->userid);
     }
-
-    /**
-     * 用户 ID
-     */
-    public function userid(): int
-    {
-        return $this->userid;
-    }
-
-    /**
-     * 用户名
-     */
-    public function userName(): string
-    {
-        if ($this->userid === 0) {
-            return '未使用';
-        }
-        if ($this->user() === null) {
-            return '用户已不存在';
-        }
-        return $this->user()->user_name;
-    }
-
-    /**
-     * 类型
-     */
-    public function type(): string
-    {
-        return match ($this->type) {
-            -1 => '充值金额',
-            -2 => '财务支出',
-            default => '已经废弃',
-        };
-    }
-
-    /**
-     * 操作
-     */
-    public function number(): string
-    {
-        return match ($this->type) {
-            -1 => '充值 ' . $this->number . ' 元',
-            -2 => '支出 ' . $this->number . ' 元',
-            default => '已经废弃',
-        };
-    }
-
-    /**
-     * 是否已经使用
-     */
-    public function isused(): string
-    {
-        return $this->isused === 1 ? '已使用' : '未使用';
-    }
-
-    /**
-     * 使用时间
-     */
-    public function usedatetime(): string
-    {
-        return $this->usedatetime > '2000-1-1 0:0:0' ? $this->usedatetime : '未使用';
-    }
 }

+ 0 - 22
src/Models/Coupon.php

@@ -4,30 +4,8 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-use function in_array;
-
 final class Coupon extends Model
 {
     protected $connection = 'default';
     protected $table = 'coupon';
-
-    public function expire(): string
-    {
-        return date('Y-m-d H:i:s', $this->attributes['expire']);
-    }
-
-    public function order($shop): bool
-    {
-        if ($this->attributes['shop'] === '') {
-            return true;
-        }
-
-        $shop_array = explode(',', $this->attributes['shop']);
-
-        if (in_array($shop, $shop_array, true)) {
-            return true;
-        }
-
-        return false;
-    }
 }

+ 0 - 9
src/Models/DetectBanLog.php

@@ -7,17 +7,8 @@ namespace App\Models;
 final class DetectBanLog extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'detect_ban_log';
 
-    /**
-     * [静态方法] 删除不存在的用户的记录
-     */
-    public static function userIsNull(DetectBanLog $DetectBanLog): void
-    {
-        self::where('user_id', $DetectBanLog->user_id)->delete();
-    }
-
     /**
      * 用户
      */

+ 0 - 25
src/Models/DetectLog.php

@@ -7,33 +7,8 @@ namespace App\Models;
 final class DetectLog extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'detect_log';
 
-    /**
-     * [静态方法] 删除不存在的节点的记录
-     */
-    public static function nodeIsNull(DetectLog $DetectLog): void
-    {
-        self::where('node_id', $DetectLog->node_id)->delete();
-    }
-
-    /**
-     * [静态方法] 删除不存在的规则的记录
-     */
-    public static function ruleIsNull(DetectLog $DetectLog): void
-    {
-        self::where('list_id', $DetectLog->list_id)->delete();
-    }
-
-    /**
-     * [静态方法] 删除不存在的用户的记录
-     */
-    public static function userIsNull(DetectLog $DetectLog): void
-    {
-        self::where('user_id', $DetectLog->user_id)->delete();
-    }
-
     /**
      * 用户
      */

+ 0 - 1
src/Models/DetectRule.php

@@ -10,7 +10,6 @@ namespace App\Models;
 final class DetectRule extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'detect_list';
 
     /**

+ 1 - 1
src/Models/Link.php

@@ -9,7 +9,7 @@ final class Link extends Model
     protected $connection = 'default';
     protected $table = 'link';
 
-    public function getUser(): ?User
+    public function user(): ?User
     {
         return User::find($this->attributes['userid']);
     }

+ 0 - 17
src/Models/LoginIp.php

@@ -10,17 +10,8 @@ namespace App\Models;
 final class LoginIp extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'login_ip';
 
-    /**
-     * [静态方法] 删除不存在的用户的记录
-     */
-    public static function userIsNull(LoginIp $LoginIp): void
-    {
-        self::where('userid', $LoginIp->userid)->delete();
-    }
-
     /**
      * 登录用户
      */
@@ -40,14 +31,6 @@ final class LoginIp extends Model
         return $this->user()->user_name;
     }
 
-    /**
-     * 登录时间
-     */
-    public function datetime(): string
-    {
-        return date('Y-m-d H:i:s', $this->datetime);
-    }
-
     /**
      * 登录成功与否
      */

+ 0 - 1
src/Models/Model.php

@@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Model as EloquentModel;
 abstract class Model extends EloquentModel
 {
     public $timestamps = false;
-
     protected $guarded = [];
 
     /**

+ 0 - 1
src/Models/OnlineLog.php

@@ -26,7 +26,6 @@ use function substr;
 final class OnlineLog extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'online_log';
 
     /**

+ 1 - 1
src/Models/PasswordReset.php

@@ -12,7 +12,7 @@ final class PasswordReset extends Model
     /**
      * 获取对应用户
      */
-    public function getUser(): ?User
+    public function user(): ?User
     {
         return User::where('email', $this->email)->first();
     }

+ 1 - 7
src/Models/Payback.php

@@ -13,13 +13,7 @@ final class Payback extends Model
 
     public function user()
     {
-        $user = User::where('id', $this->attributes['userid'])->first();
-        if ($user === null) {
-            Bought::where('id', '=', $this->attributes['id'])->delete();
-            return null;
-        }
-
-        return $user;
+        return User::where('id', $this->attributes['userid'])->first();
     }
 
     public static function rebate($user_id, $order_amount): void

+ 0 - 108
src/Models/Shop.php

@@ -19,61 +19,12 @@ use function time;
 final class Shop extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'shop';
 
     protected $casts = [
         'content' => 'array',
     ];
 
-    public function content(): string
-    {
-        $content_text = '';
-        foreach ($this->content as $key => $value) {
-            switch ($key) {
-                case 'bandwidth':
-                    $content_text .= '添加流量 ' . $value . ' G ';
-                    break;
-                case 'expire':
-                    $content_text .= ', 为账号的有效期添加 ' . $value . ' 天 ';
-                    break;
-                case 'class':
-                    $content_text .= ', 为账号升级为等级 ' . $value . ' , 有效期 ' . $this->content['class_expire'] . ' 天 ';
-                    break;
-                case 'reset':
-                    $content_text .= ', 在 ' . $this->content['reset_exp'] . ' 天内 ,每 ' . $value . ' 天重置流量为 ' . $this->content['reset_value'] . ' G ';
-                    break;
-                case 'speedlimit':
-                    if ($value === 0) {
-                        $content_text .= ', 用户端口不限速 ';
-                    } else {
-                        $content_text .= ', 用户端口限速变为' . $value . ' Mbps ';
-                    }
-                    break;
-                case 'connector':
-                    if ($value === 0) {
-                        $content_text .= ', 用户IP不限制';
-                    } else {
-                        $content_text .= ', 用户IP限制变为 ' . $value . ' 个';
-                    }
-                    break;
-                default:
-            }
-        }
-
-        return rtrim($content_text, ',');
-    }
-
-    public function bandwidth()
-    {
-        return $this->content['bandwidth'] ?? 0;
-    }
-
-    public function expire()
-    {
-        return $this->content['expire'] ?? 0;
-    }
-
     public function reset()
     {
         return $this->content['reset'] ?? 0;
@@ -89,49 +40,6 @@ final class Shop extends Model
         return $this->content['reset_exp'] ?? 0;
     }
 
-    public function trafficPackage(): bool
-    {
-        return isset($this->content['traffic_package']);
-    }
-
-    public function contentExtra(): array|int
-    {
-        if (isset($this->content['content_extra'])) {
-            $content_extra = explode(';', $this->content['content_extra']);
-            $content_extra_new = [];
-            foreach ($content_extra as $innerContent) {
-                if (! str_contains($innerContent, '-')) {
-                    $innerContent = 'check-' . $innerContent;
-                }
-                $innerContent = explode('-', $innerContent);
-                $content_extra_new[] = $innerContent;
-            }
-            return $content_extra_new;
-        }
-
-        return 0;
-    }
-
-    public function userClass()
-    {
-        return $this->content['class'] ?? 0;
-    }
-
-    public function classExpire()
-    {
-        return $this->content['class_expire'] ?? 0;
-    }
-
-    public function speedlimit()
-    {
-        return $this->content['speedlimit'] ?? 0;
-    }
-
-    public function connector()
-    {
-        return $this->content['connector'] ?? 0;
-    }
-
     public function buy($user, $is_renew = 0): void
     {
         if (isset($this->content['traffic_package'])) {
@@ -202,20 +110,4 @@ final class Shop extends Model
     {
         return $this->reset() !== 0 && $this->resetValue() !== 0 && $this->resetExp() !== 0;
     }
-
-    /*
-     * 流量是否自动重置
-     */
-    public function autoResetBandwidthString(): string
-    {
-        return $this->auto_reset_bandwidth === 0 ? '不自动重置' : '自动重置';
-    }
-
-    /*
-     * 商品状态
-     */
-    public function status(): string
-    {
-        return $this->status === 1 ? '上架' : '下架';
-    }
 }

+ 0 - 5
src/Models/TelegramSession.php

@@ -11,9 +11,4 @@ final class TelegramSession extends Model
 {
     protected $connection = 'default';
     protected $table = 'telegram_session';
-
-    public function datetime(): string
-    {
-        return date('Y-m-d H:i:s', $this->attributes['datetime']);
-    }
 }

+ 0 - 9
src/Models/UserSubscribeLog.php

@@ -9,17 +9,8 @@ use voku\helper\AntiXSS;
 final class UserSubscribeLog extends Model
 {
     protected $connection = 'default';
-
     protected $table = 'user_subscribe_log';
 
-    /**
-     * [静态方法] 删除不存在的用户的记录
-     */
-    public static function userIsNull(UserSubscribeLog $UserSubscribeLog): void
-    {
-        self::where('user_id', $UserSubscribeLog->user_id)->delete();
-    }
-
     /**
      * 用户
      */

+ 12 - 18
src/Services/Password.php

@@ -6,37 +6,31 @@ namespace App\Services;
 
 use App\Models\PasswordReset;
 use App\Utils\Tools;
-use Exception;
 use Psr\Http\Client\ClientExceptionInterface;
 use function time;
 
 final class Password
 {
-    public static function sendResetEmail($email): bool
+    /**
+     * @throws ClientExceptionInterface
+     */
+    public static function sendResetEmail($email): void
     {
         $pwdRst = new PasswordReset();
         $pwdRst->email = $email;
         $pwdRst->init_time = time();
         $pwdRst->expire_time = time() + 3600 * 24;
         $pwdRst->token = Tools::genRandomChar(64);
-        if (! $pwdRst->save()) {
-            return false;
-        }
         $subject = $_ENV['appName'] . '重置密码';
         $resetUrl = $_ENV['baseUrl'] . '/password/token/' . $pwdRst->token;
-        try {
-            Mail::send(
-                $email,
-                $subject,
-                'password/reset.tpl',
-                [
-                    'resetUrl' => $resetUrl,
-                ]
-            );
-        } catch (Exception | ClientExceptionInterface $e) {
-            return false;
-        }
 
-        return true;
+        Mail::send(
+            $email,
+            $subject,
+            'password/reset.tpl',
+            [
+                'resetUrl' => $resetUrl,
+            ]
+        );
     }
 }

+ 0 - 10
src/Utils/ResponseHelper.php

@@ -7,7 +7,6 @@ namespace App\Utils;
 use Psr\Http\Message\RequestInterface;
 use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Response;
-use function array_keys;
 use function hash;
 use function json_encode;
 
@@ -31,15 +30,6 @@ final class ResponseHelper
         ]);
     }
 
-    public static function buildTableConfig(array $data, string $uri): array
-    {
-        return [
-            'total_column' => $data,
-            'default_show_column' => array_keys($data),
-            'ajax_url' => $uri,
-        ];
-    }
-
     /**
      * Build a JSON response with ETag header.
      *

+ 46 - 1
src/Utils/Telegram.php

@@ -4,9 +4,11 @@ declare(strict_types=1);
 
 namespace App\Utils;
 
+use App\Models\TelegramSession;
 use Exception;
 use Telegram\Bot\Api;
 use Telegram\Bot\Exceptions\TelegramSDKException;
+use function time;
 
 final class Telegram
 {
@@ -14,7 +16,6 @@ final class Telegram
      * 发送讯息,默认给群组发送
      *
      * @throws TelegramSDKException
-     * @throws TelegramSDKException
      */
     public static function send(string $messageText, int $chat_id = 0): void
     {
@@ -77,4 +78,48 @@ final class Telegram
             }
         }
     }
+
+    public static function generateRandomLink(): string
+    {
+        for ($i = 0; $i < 10; $i++) {
+            $token = Tools::genRandomChar(16);
+            $session = TelegramSession::where('session_content', '=', $token)->first();
+
+            if ($session === null) {
+                return $token;
+            }
+        }
+
+        return "couldn't alloc token";
+    }
+
+    public static function verifyBindSession($token): int
+    {
+        $session = TelegramSession::where('type', '=', 0)->where('session_content', $token)
+            ->where('datetime', '>', time() - 600)->orderBy('datetime', 'desc')->first();
+
+        if ($session !== null) {
+            $uid = $session->user_id;
+            $session->delete();
+            return $uid;
+        }
+
+        return 0;
+    }
+
+    public static function addBindSession($user): string
+    {
+        $session = TelegramSession::where('type', '=', 0)->where('user_id', '=', $user->id)->first();
+
+        if ($session === null) {
+            $session = new TelegramSession();
+            $session->type = 0;
+            $session->user_id = $user->id;
+        }
+
+        $session->datetime = time();
+        $session->session_content = self::generateRandomLink();
+        $session->save();
+        return $session->session_content;
+    }
 }

+ 2 - 2
src/Utils/Telegram/Commands/StartCommand.php

@@ -6,8 +6,8 @@ namespace App\Utils\Telegram\Commands;
 
 use App\Models\Setting;
 use App\Models\User;
+use App\Utils\Telegram;
 use App\Utils\Telegram\TelegramTools;
-use App\Utils\TelegramSessionManager;
 use Telegram\Bot\Actions;
 use Telegram\Bot\Commands\Command;
 use function strlen;
@@ -83,7 +83,7 @@ final class StartCommand extends Command
 
     public function bindingAccount($SendUser, $MessageText): void
     {
-        $Uid = TelegramSessionManager::verifyBindSession($MessageText);
+        $Uid = Telegram::verifyBindSession($MessageText);
         if ($Uid === 0) {
             $text = '绑定失败了呢,经检查发现:【' . $MessageText . '】的有效期为 10 分钟,您可以在我们网站上的 **资料编辑** 页面刷新后重试.';
         } else {

+ 2 - 2
src/Utils/Telegram/Message.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Utils\Telegram;
 
 use App\Models\Setting;
-use App\Utils\TelegramSessionManager;
+use App\Utils\Telegram;
 use Telegram\Bot\Api;
 use Telegram\Bot\Exceptions\TelegramSDKException;
 use function count;
@@ -61,7 +61,7 @@ final class Message
             $MessageData = trim($this->Message->getText());
             if ($this->ChatID > 0 && strlen($MessageData) === 16) {
                 // 私聊
-                $Uid = TelegramSessionManager::verifyBindSession($MessageData);
+                $Uid = Telegram::verifyBindSession($MessageData);
                 if ($Uid === 0) {
                     $text = '绑定失败了呢,经检查发现:【' . $MessageData . '】的有效期为 10 分钟,您可以在我们网站上的 **资料编辑** 页面刷新后重试.';
                 } else {

+ 0 - 55
src/Utils/TelegramSessionManager.php

@@ -1,55 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Utils;
-
-use App\Models\TelegramSession;
-use function time;
-
-final class TelegramSessionManager
-{
-    public static function generateRandomLink(): string
-    {
-        for ($i = 0; $i < 10; $i++) {
-            $token = Tools::genRandomChar(16);
-            $Elink = TelegramSession::where('session_content', '=', $token)->first();
-            if ($Elink === null) {
-                return $token;
-            }
-        }
-
-        return "couldn't alloc token";
-    }
-
-    public static function addBindSession($user)
-    {
-        $Elink = TelegramSession::where('type', '=', 0)->where('user_id', '=', $user->id)->first();
-        if ($Elink !== null) {
-            $Elink->datetime = time();
-            $Elink->session_content = self::generateRandomLink();
-            $Elink->save();
-            return $Elink->session_content;
-        }
-
-        $NLink = new TelegramSession();
-        $NLink->type = 0;
-        $NLink->user_id = $user->id;
-        $NLink->datetime = time();
-        $NLink->session_content = self::generateRandomLink();
-        $NLink->save();
-
-        return $NLink->session_content;
-    }
-
-    public static function verifyBindSession($token)
-    {
-        $Elink = TelegramSession::where('type', '=', 0)->where('session_content', $token)->where('datetime', '>', time() - 600)->orderBy('datetime', 'desc')->first();
-        if ($Elink !== null) {
-            $uid = $Elink->user_id;
-            $Elink->delete();
-            return $uid;
-        }
-        return 0;
-    }
-}