Skip to content

Commit 945f0f1

Browse files
authored
Merge pull request #20 from rappasoft/develop
v1.2
2 parents 14aed2d + 1cf3f97 commit 945f0f1

File tree

15 files changed

+159
-15
lines changed

15 files changed

+159
-15
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.0]
16+
php: [8.0, 7.4]
1717
laravel: [8.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to `Laravel Authentication Log` will be documented in this file.
44

5+
### 1.2.0 - 2021-11-21
6+
7+
### Added
8+
9+
- Fire a successful login after a failed login on an unknown (new) device. - https://github.com/rappasoft/laravel-authentication-log/pull/15
10+
- Make the events the package is listening for configurable in the config file
11+
- Added French translation and missing location translations - https://github.com/rappasoft/laravel-authentication-log/pull/18
12+
- PHP 7.4 Support
13+
514
### 1.1.1 - 2021-10-20
615

716
### Changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.0",
19+
"php": "^7.4|^8.0",
2020
"illuminate/contracts": "^8.37",
2121
"spatie/laravel-package-tools": "^1.4.3"
2222
},

config/authentication-log.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
// The database connection where the authentication_log table resides. Leave empty to use the default
99
'db_connection' => null,
1010

11+
// The events the package listens for to log
12+
'events' => [
13+
'login' => \Illuminate\Auth\Events\Login::class,
14+
'failed' => \Illuminate\Auth\Events\Failed::class,
15+
'logout' => \Illuminate\Auth\Events\Logout::class,
16+
'logout-other-devices' => \Illuminate\Auth\Events\OtherDeviceLogout::class,
17+
],
18+
1119
'notifications' => [
1220
'new-device' => [
1321
// Send the NewDevice notification

docs/known-issues.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ title: Known Issues
33
weight: 2
44
---
55

6-
Curable:
6+
Fixed:
77

88
- [This cache store is not supported. - torann/geoip](https://github.com/Torann/laravel-geoip/issues/147#issuecomment-528414630)
9+
- When the session renews Laravel fires the Login event which results in a new login row [1](https://github.com/rappasoft/laravel-authentication-log/issues/13) [2](https://rappasoft.com/docs/laravel-authentication-log/v1/start/configuration#user-content-example-event-override)
910

1011
Unsolved:
1112

12-
- [When the session renews Laravel fires the Login event which results in a new login row](https://github.com/rappasoft/laravel-authentication-log/issues/13)
13+
- None

docs/start/configuration.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ return [
3232

3333
// The database connection where the authentication_log table resides. Leave empty to use the default
3434
'db_connection' => null,
35+
36+
// The events the package listens for to log (as of v1.3)
37+
'events' => [
38+
'login' => \Illuminate\Auth\Events\Login::class,
39+
'failed' => \Illuminate\Auth\Events\Failed::class,
40+
'logout' => \Illuminate\Auth\Events\Logout::class,
41+
'logout-other-devices' => \Illuminate\Auth\Events\OtherDeviceLogout::class,
42+
],
3543

3644
'notifications' => [
3745
'new-device' => [
@@ -84,3 +92,88 @@ class User extends Authenticatable
8492
```
8593

8694
The package will listen for Laravel's Login, Logout, Failed, and OtherDeviceLogout events.
95+
96+
## Overriding default Laravel events
97+
98+
If you would like to listen to your own events you may override them in the package config (as of v1.3).
99+
100+
### Example event override
101+
102+
You may notice that Laravel [fires a Login event when the session renews](https://github.com/laravel/framework/blob/master/src/Illuminate/Auth/SessionGuard.php#L149) if the user clicked 'remember me' when logging in. This will produce empty login rows each time which is not what we want. The way around this is to fire your own `Login` event instead of listening for Laravels.
103+
104+
You can create a Login event that takes the user:
105+
106+
```php
107+
<?php
108+
109+
namespace App\Domains\Auth\Events;
110+
111+
use Illuminate\Queue\SerializesModels;
112+
113+
class Login
114+
{
115+
use SerializesModels;
116+
117+
public $user;
118+
119+
public function __construct($user)
120+
{
121+
$this->user = $user;
122+
}
123+
}
124+
```
125+
126+
Then override it in the package config:
127+
128+
```php
129+
// The events the package listens for to log
130+
'events' => [
131+
'login' => \App\Domains\Auth\Events\Login::class,
132+
...
133+
],
134+
```
135+
136+
Then call it where you login your user:
137+
138+
```php
139+
event(new Login($user));
140+
```
141+
142+
Now the package will only register actual login events, and not session re-authentications.
143+
144+
### Overriding in Fortify
145+
146+
If you are working with Fortify and would like to register your own Login event, you can append a class to the authentication stack:
147+
148+
In FortifyServiceProvider:
149+
150+
```php
151+
Fortify::authenticateThrough(function () {
152+
return array_filter([
153+
...
154+
FireLoginEvent::class,
155+
]);
156+
});
157+
```
158+
159+
`FireLoginEvent` is just a class that fires the event:
160+
161+
```php
162+
<?php
163+
164+
namespace App\Domains\Auth\Actions;
165+
166+
use App\Domains\Auth\Events\Login;
167+
168+
class FireLoginEvent
169+
{
170+
public function handle($request, $next)
171+
{
172+
if ($request->user()) {
173+
event(new Login($request->user()));
174+
}
175+
176+
return $next($request);
177+
}
178+
}
179+
```

resources/lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
"Regards": "Regards",
1010
"There has been a failed login attempt to your :app account.": "There has been a failed login attempt to your :app account.",
1111
"Time": "Time",
12+
"Unknown City": "Unknown City",
13+
"Unknown State": "Unknown State",
1214
"Your :app account logged in from a new device.": "Your :app account logged in from a new device."
1315
}

resources/lang/fr.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"A failed login to your account": "Échec de la connexion à votre compte",
3+
"Account": "Compte",
4+
"Browser": "Navigateur",
5+
"Hello": "Bonjour",
6+
"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.",
7+
"IP Address": "Adresse IP",
8+
"Location": "Emplacement",
9+
"Regards": "Cordialement",
10+
"There has been a failed login attempt to your :app account.": "Une tentative de connexion à votre compte sur :app a échoué.",
11+
"Time": "Heure",
12+
"Unknown City": "Ville inconnue",
13+
"Unknown State": "État inconnu",
14+
"Your :app account logged in from a new device.": "Connexion à votre compte sur :app depuis un nouvel appareil."
15+
}

resources/views/emails/failed.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
> **@lang('IP Address'):** {{ $ipAddress }}<br/>
99
> **@lang('Browser'):** {{ $browser }}<br/>
1010
@if ($location && $location['default'] === false)
11-
> **@lang('Location'):** {{ $location['city'] ?? 'Unknown City' }}, {{ $location['state'], 'Unknown State' }}
11+
> **@lang('Location'):** {{ $location['city'] ?? __('Unknown City') }}, {{ $location['state'], __('Unknown State') }}
1212
@endif
1313

1414
@lang('If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.')

resources/views/emails/new.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
> **@lang('IP Address'):** {{ $ipAddress }}<br/>
99
> **@lang('Browser'):** {{ $browser }}<br/>
1010
@if ($location && $location['default'] === false)
11-
> **@lang('Location'):** {{ $location['city'] ?? 'Unknown City' }}, {{ $location['state'], 'Unknown State' }}
11+
> **@lang('Location'):** {{ $location['city'] ?? __('Unknown City') }}, {{ $location['state'], __('Unknown State') }}
1212
@endif
1313

1414
@lang('If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.')

0 commit comments

Comments
 (0)