improve login notify + migrate torrent purchase to announce

This commit is contained in:
xiaomlove
2023-04-09 14:53:15 +08:00
parent 4535ba94a4
commit 33b16ed7ac
9 changed files with 86 additions and 62 deletions
+19
View File
@@ -7,6 +7,7 @@ use App\Http\Resources\ExamUserResource;
use App\Http\Resources\UserResource;
use App\Models\ExamUser;
use App\Models\Invite;
use App\Models\LoginLog;
use App\Models\Message;
use App\Models\Setting;
use App\Models\User;
@@ -698,4 +699,22 @@ class UserRepository extends BaseRepository
return nexus_trans('invite.send_allow_text');
}
public function saveLoginLog(int $uid, string $ip, string $client = '', bool $notify = false)
{
$locationInfo = get_ip_location_from_geoip($ip);
$loginLog = LoginLog::query()->create([
'ip' => $ip,
'uid' => $uid,
'country' => $locationInfo['country_en'] ?? '',
'city' => $locationInfo['city_en'] ?? '',
'client' => $client,
]);
if ($notify) {
$command = sprintf("user:login_notify --this_id=%s", $loginLog->id);
do_log("[LOGIN_NOTIFY], user: $uid, $command");
executeCommand($command, "string", true, false);
}
return $loginLog;
}
}