Skip to content

Commit

Permalink
feat: 投稿、審核時,紀錄 IP 與 UA,免得被搞還以為是正常使用者
Browse files Browse the repository at this point in the history
  • Loading branch information
Kantai235 committed Aug 17, 2024
1 parent b7f538d commit ab948b2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public function article(PublishArticleRequest $request)
'ads' => $picture['ads'],
];

$data['ip_address'] = $request->ip();
$data['user_agent'] = $request->header('User-Agent');

/**
* 將文字投稿寫入
*/
Expand Down Expand Up @@ -124,6 +127,9 @@ public function picture(PublishPictureRequest $request)
'type' => 'picture',
];

$data['ip_address'] = $request->ip();
$data['user_agent'] = $request->header('User-Agent');

/**
* 將圖片投稿寫入
*/
Expand Down
18 changes: 10 additions & 8 deletions app/Domains/Social/Http/Controllers/Api/Cards/ReviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function voting(Request $request, Cards $card, $status)
$platforms = Platform::where('action', Platform::ACTION_PUBLISH)
->active()
->get();

/**
* 根據社群平台逐一發佈
*/
Expand All @@ -123,49 +123,49 @@ public function voting(Request $request, Cards $card, $status)
case Platform::TYPE_FACEBOOK:
dispatch(new FacebookPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Twitter 的 Job
*/
case Platform::TYPE_TWITTER:
dispatch(new TwitterPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Plurk 的 Job
*/
case Platform::TYPE_PLURK:
dispatch(new PlurkPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Discord 的 Job
*/
case Platform::TYPE_DISCORD:
dispatch(new DiscordPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Tumblr 的 Job
*/
case Platform::TYPE_TUMBLR:
dispatch(new TumblrPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Telegram 的 Job
*/
case Platform::TYPE_TELEGRAM:
dispatch(new TelegramPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Bsky 的 Job
*/
case Platform::TYPE_BSKY:
dispatch(new BskyPublishJob($card, $platform))->onQueue('highest');
break;

/**
* 其它並不在支援名單當中的社群
*/
Expand All @@ -186,6 +186,8 @@ public function voting(Request $request, Cards $card, $status)
'model_id' => $request->user()->id,
'card_id' => $card->id,
'point' => ((bool) $status) ? 1 : -1,
'ip_address' => $request->ip(),
'user_agent' => $request->header('User-Agent'),
]);

return response()->json([
Expand Down
2 changes: 2 additions & 0 deletions app/Domains/Social/Models/Cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Cards extends Model
'blockade_by',
'blockade_remarks',
'blockade_at',
'ip_address',
'user_agent',
];

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Domains/Social/Models/Reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Reviews extends Model
'card_id',
'point',
'config',
'ip_address',
'user_agent',
];

/**
Expand Down
4 changes: 4 additions & 0 deletions app/Domains/Social/Services/CardsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public function store(array $data = []): Cards
'content' => $data['content'],
'config' => $data['config'],
'picture' => $data['picture'],
'ip_address' => $data['ip_address'],
'user_agent' => $data['user_agent'],
]);
} catch (Exception $e) {
DB::rollBack();
Expand Down Expand Up @@ -262,6 +264,8 @@ protected function createCards(array $data = []): Cards
'picture' => $this->createImage($data['picture']),
'active' => $data['active'] ?? false,
'blockade' => $data['blockade'] ?? false,
'ip_address' => $data['ip_address'] ?? null,
'user_agent' => $data['user_agent'] ?? null,
]);
}

Expand Down
4 changes: 4 additions & 0 deletions app/Domains/Social/Services/ReviewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public function store(array $data): Reviews
'model_id' => $data['model_id'],
'card_id' => $data['card_id'],
'point' => $data['point'],
'ip_address' => $data['ip_address'],
'user_agent' => $data['user_agent'],
]);
} catch (Exception $e) {
DB::rollBack();
Expand Down Expand Up @@ -197,6 +199,8 @@ protected function createReview(array $data = []): Reviews
'card_id' => $data['card_id'],
'point' => $data['point'],
'config' => isset($data['config']) ? json_encode($data['config']) : '{}',
'ip_address' => $data['ip_address'] ?? null,
'user_agent' => $data['user_agent'] ?? null,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public function up(): void
$table->unsignedBigInteger('blockade_by')->nullable()->comment('被誰封鎖');
$table->string('blockade_remarks')->nullable()->comment('封鎖原因');
$table->timestamp('blockade_at')->nullable()->comment('在什麼時候被封鎖');
$table->string('ip_address')->nullable()->comment('IP Address');
$table->string('user_agent')->nullable()->comment('User Agent');
$table->timestamps();
$table->softDeletes();

Expand Down Expand Up @@ -146,6 +148,8 @@ public function up(): void
$table->unsignedBigInteger('card_id')->comment('文章 ID');
$table->integer('point')->default(0)->comment('票數權重');
$table->json('config')->comment('設定');
$table->string('ip_address')->nullable()->comment('IP Address');
$table->string('user_agent')->nullable()->comment('User Agent');
$table->timestamps();
$table->softDeletes();

Expand Down
10 changes: 10 additions & 0 deletions database/seeders/Social/SocialCardsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function run()
'blockade_by' => null,
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand All @@ -72,6 +74,8 @@ public function run()
'blockade_by' => null,
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand Down Expand Up @@ -106,6 +110,8 @@ public function run()
'blockade_by' => null,
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand All @@ -131,6 +137,8 @@ public function run()
'blockade_by' => null,
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand All @@ -156,6 +164,8 @@ public function run()
'blockade_by' => null,
'blockade_remarks' => null,
'blockade_at' => null,
'ip_address' => '127.0.0.1',
'user_agent' => 'Mozilla/5.0',
]);

Cards::create([
Expand Down

0 comments on commit ab948b2

Please sign in to comment.