Track IP changes

This commit is contained in:
Miguel Nogueira 2021-01-06 02:11:47 +00:00
parent 5cf6b2b241
commit 3b28bf1cfe
Signed by: miguel456
GPG Key ID: 2CF61B825316C6A0
2 changed files with 35 additions and 0 deletions

View File

@ -25,6 +25,7 @@ use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class LoginController extends Controller
{
@ -77,4 +78,17 @@ class LoginController extends Controller
return $this->originalAttemptLogin($request);
}
public function authenticated(Request $request, User $user)
{
if ($user->originalIP !== $request->ip())
{
Log::alert('User IP address changed from last login. Updating.', [
'prev' => $user->originalIP,
'new' => $request->ip()
]);
$user->originalIP = $request->ip();
$user->save();
}
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class IPHistoryMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
return $next($request);
}
}