Browse Source

feat: add api_token to user table

Cat 2 years ago
parent
commit
eb6ca2cf1e

+ 1 - 0
db/migrations/20000101000000_init_database.php.new

@@ -64,6 +64,7 @@ final class InitDatabase extends AbstractMigration
             ->addColumn('forbidden_port', 'string', [ 'default' => '' ])
             ->addColumn('auto_reset_day', 'integer', [ 'default' => 0])
             ->addColumn('auto_reset_bandwidth', 'decimal', [ 'default' => '0.00', 'precision' => 12, 'scale' => 2 ])
+            ->addColumn('api_token', 'uuid', [ 'comment' => 'API 密钥', 'null' => false, 'default' => '' ])
             ->addIndex([ 'user_name' ])
             ->create();
 

+ 1 - 1
db/migrations/20221130005800_add_user_node_iplimit.php

@@ -10,7 +10,7 @@ final class AddUserNodeIplimit extends AbstractMigration
     {
         if (! $this->table('user')->hasColumn('node_iplimit')) {
             $this->table('user')
-                ->addColumn('node_iplimit', 'integer', [ 'comment' => '同时可连接IP数', 'default' => 0 ])
+                ->addColumn('node_iplimit', 'smallinteger', [ 'comment' => '同时可连接IP数', 'default' => 0, 'signed' => false, 'null' => false ])
                 ->save();
         }
     }

+ 24 - 0
db/migrations/20221208132600_add_user_api_token.php

@@ -0,0 +1,24 @@
+<?php
+
+declare(strict_types=1);
+
+use Phinx\Migration\AbstractMigration;
+
+final class AddUserApiToken extends AbstractMigration
+{
+    public function up(): void
+    {
+        if (! $this->table('user')->hasColumn('api_token')) {
+            $this->table('user')
+                ->addColumn('api_token', 'uuid', [ 'comment' => 'API 密钥', 'null' => false, 'default' => '' ])
+                ->save();
+        }
+    }
+
+    public function down(): void
+    {
+        $this->table('user')
+            ->removeColumn('api_token')
+            ->save();
+    }
+}

+ 0 - 1
src/Controllers/LinkController.php

@@ -8,7 +8,6 @@ namespace App\Controllers;
 
 use App\Models\Link;
 use App\Models\UserSubscribeLog;
-use App\Utils\Tools;
 use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Request;
 use Slim\Http\Response;

+ 0 - 1
src/Controllers/UserController.php

@@ -16,7 +16,6 @@ use App\Models\Node;
 use App\Models\Payback;
 use App\Models\Setting;
 use App\Models\StreamMedia;
-use App\Models\Token;
 use App\Models\User;
 use App\Models\UserSubscribeLog;
 use App\Services\Auth;

+ 2 - 5
src/Models/User.php

@@ -4,7 +4,6 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-use App\Controllers\LinkController;
 use App\Services\Config;
 use App\Services\Mail;
 use App\Utils\GA;
@@ -44,9 +43,7 @@ final class User extends Model
      * @var array
      */
     protected $casts = [
-        't' => 'int',
         'port' => 'int',
-        'enable' => 'int',
         'is_admin' => 'boolean',
         'is_multi_user' => 'int',
         'node_speedlimit' => 'float',
@@ -180,7 +177,7 @@ final class User extends Model
     }
 
     /**
-     * 生成新的UUID
+     * 生成新的 UUID
      */
     public function generateUUID($s): bool
     {
@@ -357,7 +354,7 @@ final class User extends Model
      */
     public function getSublink()
     {
-        return LinkController::generateSSRSubCode($this->id);
+        return Tools::generateSSRSubCode($this->id);
     }
 
     /**

+ 0 - 1
src/Utils/Telegram/Callbacks/Callback.php

@@ -4,7 +4,6 @@ declare(strict_types=1);
 
 namespace App\Utils\Telegram\Callbacks;
 
-use App\Controllers\LinkController;
 use App\Controllers\SubController;
 use App\Models\InviteCode;
 use App\Models\Ip;