From 4535ba94a40e6e73e598043fcd4bdd348fa027da Mon Sep 17 00:00:00 2001
From: xiaomlove
Date: Sun, 9 Apr 2023 02:33:37 +0800
Subject: [PATCH] enable login notify
---
app/Console/Commands/Test.php | 36 +++++++++++-------------
app/Console/Commands/UserLoginNotify.php | 4 +++
public/takelogin.php | 2 +-
resources/lang/en/message.php | 4 +--
resources/lang/zh_CN/message.php | 4 +--
resources/lang/zh_TW/message.php | 4 +--
6 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php
index 471408e9..b79ac22d 100644
--- a/app/Console/Commands/Test.php
+++ b/app/Console/Commands/Test.php
@@ -13,6 +13,7 @@ use App\Models\ExamProgress;
use App\Models\ExamUser;
use App\Models\HitAndRun;
use App\Models\Invite;
+use App\Models\LoginLog;
use App\Models\Medal;
use App\Models\Peer;
use App\Models\SearchBox;
@@ -96,26 +97,21 @@ class Test extends Command
*/
public function handle()
{
- $rep = new MeiliSearchRepository();
-// $r = $rep->doImportFromDatabase();
-// dd($r);
-// $r = $rep->import();
-
- $r = $rep->search([
- 'search' => '200',
- 'spstate' => 0,
- 'incldead' => 0,
- 'mode' => 4,
-// 'cat401' => 1,
- 'sort' => '4',
- 'type' => 'desc',
- 'search_mode' => 0,
- 'inclbookmarked' => 0,
- 'approval_status' => 1,
-// 'size_end' => 20,
-// 'added_end' => '2023-02-11',
- ], 1, 'incldead=0&spstate=1&inclbookmarked=0&approval_status=1&size_begin=&size_end=&seeders_begin=&seeders_end=&leechers_begin=&leechers_end=×_completed_begin=×_completed_end=&added_begin=&added_end=&search=200&search_area=0&search_mode=0');
- dd($r);
+ $thisLoginLog = LoginLog::query()->findOrFail(10);
+ $lastLoginLog = LoginLog::query()->findOrFail(9);
+ $user = User::query()->findOrFail(1, User::$commonFields);
+ $locale = $user->locale;
+ $toolRep = new ToolRepository();
+ $subject = nexus_trans('message.login_notify.subject', ['site_name' => Setting::get('basic.SITENAME')], $locale);
+ $body = nexus_trans('message.login_notify.body', [
+ 'this_login_time' => $thisLoginLog->created_at,
+ 'this_ip' => $thisLoginLog->ip,
+ 'this_location' => sprintf('%s·%s', $thisLoginLog->city, $thisLoginLog->country),
+ 'last_login_time' => $lastLoginLog->created_at,
+ 'last_ip' => $lastLoginLog->ip,
+ 'last_location' => sprintf('%s·%s', $lastLoginLog->city, $lastLoginLog->country),
+ ], $locale);
+ dd($body);
}
}
diff --git a/app/Console/Commands/UserLoginNotify.php b/app/Console/Commands/UserLoginNotify.php
index 5a8d7e96..a246e9a1 100644
--- a/app/Console/Commands/UserLoginNotify.php
+++ b/app/Console/Commands/UserLoginNotify.php
@@ -32,6 +32,10 @@ class UserLoginNotify extends Command
$thisId = $this->option('this_id');
$lastId = $this->option('last_id');
$this->info("thisId: $thisId, lastId: $lastId");
+ if (!$thisId || !$lastId) {
+ $this->error("require option --this_id=? and --last_id=?");
+ return Command::FAILURE;
+ }
SendLoginNotify::dispatch($thisId, $lastId);
return Command::SUCCESS;
}
diff --git a/public/takelogin.php b/public/takelogin.php
index 694c92ff..303f66b1 100644
--- a/public/takelogin.php
+++ b/public/takelogin.php
@@ -53,7 +53,7 @@ if (
) {
$command = sprintf("user:login_notify --this_id=%s --last_id=%s", $thisLoginLog->id, $lastLoginLog->id);
do_log("[LOGIN_NOTIFY], user: {$row['id']}, $command");
-// executeCommand($command, "string", true, false);
+ executeCommand($command, "string", true, false);
}
if ($row["enabled"] == "no")
bark($lang_takelogin['std_account_disabled']);
diff --git a/resources/lang/en/message.php b/resources/lang/en/message.php
index b42777a1..18ac31e8 100644
--- a/resources/lang/en/message.php
+++ b/resources/lang/en/message.php
@@ -34,8 +34,8 @@ return [
'login_notify' => [
'subject' => ':site_name Offsite login alert',
'body' => <<
+Last login time::last_login_time, IP::last_ip, location::last_location.
If it is not your own operation, the account password may have been leaked, please change it in time!
BODY,
],
diff --git a/resources/lang/zh_CN/message.php b/resources/lang/zh_CN/message.php
index 1c83cc64..9123fdff 100644
--- a/resources/lang/zh_CN/message.php
+++ b/resources/lang/zh_CN/message.php
@@ -34,8 +34,8 @@ return [
'login_notify' => [
'subject' => ':site_name 异地登录提醒',
'body' => <<