Skip to content

Commit

Permalink
Merge pull request #75 from rappasoft/develop
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
rappasoft authored Feb 23, 2023
2 parents 9cba918 + 3938d57 commit 6ab9419
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0, 8.1]
laravel: [9.*]
php: [8.1]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
testbench: 7.0
- laravel: 10.*
testbench: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

### 3.0.0 - 2023-02-23

- Laravel 10 Support - https://github.com/rappasoft/laravel-authentication-log/pull/70
- Use null safe/chaining operator - https://github.com/rappasoft/laravel-authentication-log/pull/57
- Optimize Other Devices Logout Listener - https://github.com/rappasoft/laravel-authentication-log/pull/52

### 2.0.0 - 2022-02-19

### Added
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ See the [documentation](https://rappasoft.com/docs/laravel-authentication-log) f
:---------|:------------------
8.x | 1.x
9.x | 2.x
10.x | 3.x

## Installation

```bash
composer require rappasoft/laravel-authentication-log
```

## Testing

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
}
],
"require": {
"php": "^8.0",
"illuminate/contracts": "^9.0",
"php": "^8.1",
"illuminate/contracts": "^10.0",
"spatie/laravel-package-tools": "^1.4.3"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/OtherDeviceLogoutListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function handle($event): void
]);
}

foreach ($user->authentications()->whereLoginSuccessful(true)->get() as $log) {
foreach ($user->authentications()->whereLoginSuccessful(true)->whereNull('logout_at')->get() as $log) {
if ($log->id !== $authenticationLog->id) {
$log->update([
'cleared_by_user' => true,
Expand Down
7 changes: 2 additions & 5 deletions src/Models/AuthenticationLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ class AuthenticationLog extends Model
'cleared_by_user' => 'boolean',
'location' => 'array',
'login_successful' => 'boolean',
];

protected $dates = [
'login_at',
'logout_at',
'login_at' => 'datetime',
'logout_at' => 'datetime',
];

public function __construct(array $attributes = [])
Expand Down
12 changes: 6 additions & 6 deletions src/Traits/AuthenticationLoggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ public function notifyAuthenticationLogVia(): array

public function lastLoginAt()
{
return optional($this->authentications()->first())->login_at;
return $this->authentications()->first()?->login_at;
}

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

public function lastLoginIp()
{
return optional($this->authentications()->first())->ip_address;
return $this->authentications()->first()?->ip_address;
}

public function lastSuccessfulLoginIp()
{
return optional($this->authentications()->whereLoginSuccessful(true)->first())->ip_address;
return $this->authentications()->whereLoginSuccessful(true)->first()?->ip_address;
}

public function previousLoginAt()
{
return optional($this->authentications()->skip(1)->first())->login_at;
return $this->authentications()->skip(1)->first()?->login_at;
}

public function previousLoginIp()
{
return optional($this->authentications()->skip(1)->first())->ip_address;
return $this->authentications()->skip(1)->first()?->ip_address;
}
}

0 comments on commit 6ab9419

Please sign in to comment.