Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ return new class extends Migration
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->timestamp('login_at')->nullable();
$table->string('login_url')->nullable();
$table->boolean('login_successful')->default(false);
$table->timestamp('logout_at')->nullable();
$table->boolean('cleared_by_user')->default(false);
Expand Down
2 changes: 2 additions & 0 deletions docs/usage/getting-logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ User::find(1)->lastSuccessfulLoginAt();
User::find(1)->lastLoginIp();

User::find(1)->lastSuccessfulLoginIp();

User::find(1)->lastLoginUrl();
```

Get the user's previous login time & IP address (ignoring the current login):
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Hello!": "Hello!",
"If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.": "If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.",
"IP Address:": "IP Address:",
"Login url:": "Login url:",
"Location:": "Location:",
"Regards,": "Regards,",
"There has been a failed login attempt to your :app account.": "There has been a failed login attempt to your :app account.",
Expand Down
1 change: 1 addition & 0 deletions resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Hello!": "Bonjour,",
"If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.": "Si c’était vous, vous pouvez ignorer cette alerte. Si vous soupçonnez une activité suspecte sur votre compte, veuillez modifier votre mot de passe.",
"IP Address:": "Adresse IP :",
"Login url:": "URL de connexion :",
"Location:": "Emplacement :",
"Regards,": "Cordialement,",
"There has been a failed login attempt to your :app account.": "Une tentative de connexion à votre compte sur :app a échoué.",
Expand Down
1 change: 1 addition & 0 deletions resources/lang/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Browser:": "Navegador:",
"If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.": "Se foi você, pode ignorar este alerta. Se você suspeitar de qualquer atividade suspeita em sua conta, altere sua senha.",
"IP Address:": "Endereço de IP:",
"Login url:": "URL de login:",
"Location:": "Localização:",
"Regards,": "Obrigado,",
"There has been a failed login attempt to your :app account.": "Houve uma falha na tentativa de login em seu :app conta.",
Expand Down
1 change: 1 addition & 0 deletions src/Listeners/FailedLoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function handle($event): void
'ip_address' => $ip,
'user_agent' => $this->request->userAgent(),
'login_at' => now(),
'login_url' => $this->request->fullUrl(),
'login_successful' => false,
'location' => config('authentication-log.notifications.new-device.location') ? optional(geoip()->getLocation($ip))->toArray() : null,
]);
Expand Down
1 change: 1 addition & 0 deletions src/Listeners/LoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function handle($event): void
'ip_address' => $ip,
'user_agent' => $userAgent,
'login_at' => now(),
'login_url' => $this->request->fullUrl(),
'login_successful' => true,
'location' => config('authentication-log.notifications.new-device.location') ? optional(geoip()->getLocation($ip))->toArray() : null,
]);
Expand Down
2 changes: 2 additions & 0 deletions src/Models/AuthenticationLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property string|null $ip_address
* @property string|null $user_agent
* @property \Illuminate\Support\Carbon|null $login_at
* @property string|null $login_url
* @property bool $login_successful
* @property \Illuminate\Support\Carbon|null $logout_at
* @property bool $cleared_by_user
Expand All @@ -27,6 +28,7 @@ class AuthenticationLog extends Model
'ip_address',
'user_agent',
'login_at',
'login_url',
'login_successful',
'logout_at',
'cleared_by_user',
Expand Down
5 changes: 5 additions & 0 deletions src/Traits/AuthenticationLoggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function lastLoginAt()
return $this->authentications()->first()?->login_at;
}

public function lastLoginUrl()
{
return $this->authentications()->first()?->login_url;
}

public function lastSuccessfulLoginAt()
{
return $this->authentications()->whereLoginSuccessful(true)->first()?->login_at;
Expand Down