Added Device and UserIp models and migrations to store device fingerprints and user IPs with expiration. Updated ShowSavingIp Livewire component and view to capture and persist both IP and device fingerprint. Introduced a scheduled command to clean expired user IPs and registered it in the console kernel. Removed the old migration for storing IPs directly on the users table.
59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
use Livewire\Component;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Models\UserIp;
|
|
use Carbon\Carbon;
|
|
use App\Models\Device;
|
|
|
|
class ShowSavingIp extends Component
|
|
{
|
|
public $ip_address;
|
|
public $device_fingerprint;
|
|
|
|
protected $listeners = ['setDeviceData'];
|
|
|
|
public function setDeviceData($data)
|
|
{
|
|
$this->ip_address = $data['ip'] ?? null;
|
|
$this->device_fingerprint = $data['fingerprint'] ?? null;
|
|
|
|
$user = Auth::user();
|
|
if (!$user) return;
|
|
|
|
// Guardar IP pública temporal (12h)
|
|
if ($this->ip_address) {
|
|
UserIp::updateOrCreate(
|
|
[
|
|
'user_id' => $user->id,
|
|
'ip_address' => $this->ip_address,
|
|
],
|
|
[
|
|
'expires_at' => Carbon::now()->addHours(12),
|
|
]
|
|
);
|
|
}
|
|
|
|
// Guardar fingerprint permanente del dispositivo
|
|
if ($this->device_fingerprint) {
|
|
Device::updateOrCreate(
|
|
[
|
|
'fingerprint' => $this->device_fingerprint,
|
|
],
|
|
[
|
|
'user_id' => $user->id,
|
|
'last_seen_at' => now(),
|
|
]
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.show-saving-ip');
|
|
}
|
|
}
|