cleaniquecoders / laravel-expiry
Enable expiry on user's account and user's password.
Fund package maintenance!
Nasrul Hazim
Requires
- php: ^8.1 | ^8,2 | ^8.3
- doctrine/dbal: ^3.0
- illuminate/auth: ^9.0 | ^10.0 | ^11.0
- illuminate/support: ^9.0 | ^10.0 | ^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2024-12-10 01:32:54 UTC
README
cleaniquecoders/laravel-expiry
is a Laravel package that enables expiration for user accounts and passwords with seamless middleware and event-driven support.
Features
- Account Expiry: Middleware to check and handle expired accounts.
- Password Expiry: Middleware to enforce password expiration policies.
- Event Listeners: Automatically trigger events when accounts or passwords expire.
Installation
Install the package via Composer:
composer require cleaniquecoders/laravel-expiry
Publish and run the migration files to add the necessary expiry columns:
php artisan vendor:publish --tag=laravel-expiry-migrations php artisan migrate
Middleware Registration
The package automatically registers the following middleware in your application:
account.expiry
: Handles account expiry checks.password.expiry
: Handles password expiry checks.
Usage
Apply Middleware
Use the middleware in your routes to enforce expiry checks:
Route::middleware(['account.expiry', 'password.expiry'])->group(function () { Route::get('/protected-route', [SomeController::class, 'index']); });
Event Listeners
The package provides a configuration-driven approach to managing event listeners. By default, the following events and listeners are configured:
Default Event-to-Listener Mapping
The configuration (config/laravel-expiry.php
) includes the following mappings:
'events' => [ \CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount::class => [ \CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired::class, ], \CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword::class => [ \CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired::class, ], ],
Handling Events
The package automatically registers these events and listeners. You can modify or extend the behaviour by updating the configuration file.
For example, when a user's account or password expires:
- The
ExpiredAccount
orExpiredPassword
event is triggered. - The
LogoutOnExpired
listener handles these events by logging the user out.
Customising Listeners
To add custom listeners for these events, update the configuration file (config/laravel-expiry.php
):
'events' => [ \CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount::class => [ \App\Listeners\YourCustomListener::class, ], \CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword::class => [ \App\Listeners\YourCustomListener::class, ], ],
With this setup, the package makes it easy to integrate custom logic for handling expiry events.
Testing
To run the test suite, use the following command:
vendor/bin/pest --testdox
The package is fully tested with PestPHP to ensure reliability.
Contributing
Thank you for considering contributing to cleaniquecoders/laravel-expiry
. Contributions are welcome and appreciated!
Reporting Bugs
If you find a bug, you can either:
- Submit a pull request with a failing test case.
- Create an issue describing the problem clearly with steps to reproduce it.
Coding Style
The package follows PSR-2 coding standards and PSR-4 autoloading.
License
This package is open-source software licensed under the MIT license.