feat(auth): block admin login IP after 4 failures for 20 min, email login alerts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fe68171aa7
commit
e34362b9bd
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('admin_login_blocks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('ip', 45)->unique();
|
||||
$table->unsignedInteger('failed_attempts')->default(0);
|
||||
$table->string('last_username', 191)->nullable();
|
||||
$table->string('user_agent', 500)->nullable();
|
||||
$table->timestamp('last_failed_at')->nullable();
|
||||
$table->timestamp('blocked_until')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('admin_login_blocks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use Database\Seeders\TemplateSeeder;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
(new TemplateSeeder())->seedScenarioIfMissing('admin_login_alert');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::table('template')->where('scenario', 'admin_login_alert')->delete();
|
||||
}
|
||||
};
|
||||
@@ -166,6 +166,21 @@ final class AdminTemplates
|
||||
. T::note('{{description}}', 'Nội dung:')
|
||||
. T::button('{{ticket_url}}', 'XEM TICKET'),
|
||||
],
|
||||
[
|
||||
'scenario' => 'admin_login_alert',
|
||||
'name' => '[Admin] Có người đăng nhập trang quản trị',
|
||||
'subject' => '[ADMIN] {{admin_username}} đăng nhập trang quản trị từ IP {{client_ip}}',
|
||||
'body' => T::title('Có người vừa đăng nhập trang quản trị')
|
||||
. T::paragraph('Tài khoản quản trị trên hệ thống <strong>{{company_name}}</strong> vừa đăng nhập thành công.')
|
||||
. T::infoTable([
|
||||
'Nhân viên' => '{{admin_name}}',
|
||||
'Tài khoản' => '{{admin_username}}',
|
||||
'Thời gian' => '{{login_time}}',
|
||||
'Địa chỉ IP' => '{{client_ip}}',
|
||||
'Trình duyệt' => '{{user_agent}}',
|
||||
])
|
||||
. T::note('Nếu đây không phải nhân sự của công ty, hãy đổi mật khẩu tài khoản này và khoá tài khoản ngay trong mục Nhân sự.', 'Lưu ý:'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ final class SubjectFormat
|
||||
'admin_trial_registration_request' => ['[ADMIN] yêu cầu dùng thử Cloud VPS', null, 'customer_name'],
|
||||
'admin_manual_deposit_pending' => ['[ADMIN] yêu cầu nạp tiền chờ duyệt {{transaction_code}}', null, 'customer_name'],
|
||||
'admin_ticket_notification' => ['[ADMIN] ticket mới #{{ticket_num}}', null, 'customer_name'],
|
||||
'admin_login_alert' => ['[ADMIN] {{admin_username}} đăng nhập trang quản trị từ IP {{client_ip}}', null, null],
|
||||
'admin_payment_received' => ['[ADMIN] khách hàng thanh toán {{payment_type}} #{{reference}}', null, 'customer_name'],
|
||||
'admin_service_renewed' => ['[ADMIN] {{admin_name}} gia hạn dịch vụ', 'product_name', 'customer_name'],
|
||||
'customer_signup_verify' => ['[ADMIN] đơn hàng mới #{{order_num}}', null, 'customer_name'],
|
||||
|
||||
@@ -112,6 +112,10 @@ final class TemplateVariables
|
||||
'status_line' => ['Tình trạng hạn thanh toán', 'string', 'Hoá đơn sẽ đến hạn sau 3 ngày.'],
|
||||
'paid_row' => ['[Tự động] Dòng đã thanh toán', 'html', ''],
|
||||
'transaction_code' => ['Mã giao dịch', 'string', 'NAP20261008001'],
|
||||
'admin_username' => ['Tài khoản quản trị', 'string', 'admin'],
|
||||
'login_time' => ['Thời gian đăng nhập', 'string', '23/10/2026 08:30:00'],
|
||||
'client_ip' => ['Địa chỉ IP', 'string', '203.113.10.20'],
|
||||
'user_agent' => ['Trình duyệt / thiết bị', 'string', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/141.0'],
|
||||
'amount_formatted' => ['Số tiền', 'string', '500,000'],
|
||||
'payment_type' => ['Loại thanh toán', 'string', 'Hóa đơn'],
|
||||
'reference' => ['Mã tham chiếu', 'string', 'DH20261017001'],
|
||||
|
||||
Reference in New Issue
Block a user