-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Start replacing old Logins log * Remove a couple of old panel widgets * Register login activity and jobs * Update model helpers * Create/register Last Login widget * Update weekly report email * Add job tests * Create login activity job, factory, and seeding * Test pruning job * Add login activity to dashboard * Update CHANGELOG
- Loading branch information
Showing
28 changed files
with
543 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\LoginActivityResource\Pages; | ||
use App\Filament\Resources\LoginActivityResource\RelationManagers; | ||
use App\Models\LoginActivity; | ||
use Filament\Facades\Filament; | ||
use Filament\Resources\Resource; | ||
use Filament\Support\Colors\Color; | ||
use Filament\Tables\Columns\IconColumn; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Filters\SelectFilter; | ||
use Filament\Tables\Table; | ||
|
||
class LoginActivityResource extends Resource | ||
{ | ||
protected static string|null $model = LoginActivity::class; | ||
|
||
protected static string|null $navigationGroup = 'Administration'; | ||
|
||
protected static string|null $navigationIcon = 'm-clipboard-document-list'; | ||
|
||
protected static string|null $navigationLabel = 'Login Activity'; | ||
|
||
protected static int|null $navigationSort = 2; | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('created_at') | ||
->label('Time') | ||
->dateTime() | ||
->sortable(), | ||
|
||
TextColumn::make('email') | ||
->color(fn ($state) => match ($state) { | ||
Filament::auth()->user()->email => 'white', | ||
default => Color::Neutral, | ||
}) | ||
->searchable(isIndividual: true, isGlobal: false), | ||
|
||
IconColumn::make('succeeded') | ||
->boolean(), | ||
|
||
TextColumn::make('info') | ||
->searchable(isIndividual: true, isGlobal: false), | ||
|
||
TextColumn::make('ip_address') | ||
->searchable(isIndividual: true, isGlobal: false) | ||
->fontFamily('mono'), | ||
]) | ||
->filters([ | ||
SelectFilter::make('succeeded') | ||
->options([ | ||
true => 'Succeeded', | ||
false => 'Failed', | ||
]), | ||
]) | ||
->actions([]) | ||
->bulkActions([]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListLoginActivities::route('/'), | ||
]; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/Filament/Resources/LoginActivityResource/Pages/ListLoginActivities.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\LoginActivityResource\Pages; | ||
|
||
use App\Filament\Resources\LoginActivityResource; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListLoginActivities extends ListRecords | ||
{ | ||
protected static string $resource = LoginActivityResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Models\LoginActivity; | ||
use Carbon\Carbon; | ||
use Filament\Widgets\Widget; | ||
|
||
class LastLoginWidget extends Widget | ||
{ | ||
protected int|string|array $columnSpan = 2; | ||
|
||
protected static string $view = 'filament.widgets.last-login-widget'; | ||
|
||
public readonly Carbon $time; | ||
public readonly string $ip_address; | ||
|
||
public function mount() | ||
{ | ||
$latest = LoginActivity::succeeded()->latest()->first(); | ||
|
||
$this->time = $latest->created_at; | ||
$this->ip_address = $latest->ip_address; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\LoginActivity; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
class LoginFailed | ||
{ | ||
use Dispatchable; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct( | ||
#[\SensitiveParameter] public readonly string $email, | ||
public readonly string|null $info, | ||
#[\SensitiveParameter] public readonly string $ip_address, | ||
) {} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
LoginActivity::create([ | ||
'email' => $this->email, | ||
'succeeded' => false, | ||
'info' => $this->info, | ||
'ip_address' => $this->ip_address, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\LoginActivity; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
class LoginSucceeded | ||
{ | ||
use Dispatchable; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct( | ||
#[\SensitiveParameter] public readonly string $email, | ||
#[\SensitiveParameter] public readonly string $ip_address, | ||
) {} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
LoginActivity::create([ | ||
'email' => $this->email, | ||
'succeeded' => true, | ||
'ip_address' => $this->ip_address, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\LoginActivity; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
|
||
class PruneLoginActivityJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable; | ||
|
||
public function __construct() {} | ||
|
||
public function handle(): void | ||
{ | ||
LoginActivity::whereDate( | ||
'created_at', | ||
'<=', | ||
now()->startOfDay() | ||
->subDays(config('auth.activity.days_to_keep')) | ||
)->delete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.