|
1 |
| -[](https://packagist.org/packages/cleaniquecoders/laravel-expiry) [](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/phpstan.yml) [](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/run-tests.yml) [](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/fix-styling.yml) [](https://packagist.org/packages/cleaniquecoders/laravel-expiry) |
| 1 | +# Laravel Expiry |
2 | 2 |
|
3 |
| -## Laravel Expiry |
| 3 | +[](https://packagist.org/packages/cleaniquecoders/laravel-expiry) [](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/phpstan.yml) [](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/run-tests.yml) [](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/fix-styling.yml) [](https://packagist.org/packages/cleaniquecoders/laravel-expiry) |
4 | 4 |
|
5 |
| -Enable expiry on user's account and user's password. |
| 5 | +`cleaniquecoders/laravel-expiry` is a Laravel package that enables expiration for user accounts and passwords with seamless middleware and event-driven support. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Account Expiry**: Middleware to check and handle expired accounts. |
| 12 | +- **Password Expiry**: Middleware to enforce password expiration policies. |
| 13 | +- **Event Listeners**: Automatically trigger events when accounts or passwords expire. |
| 14 | + |
| 15 | +--- |
6 | 16 |
|
7 | 17 | ## Installation
|
8 | 18 |
|
9 |
| -In order to install `cleaniquecoders/laravel-expiry` in your Laravel project, just run the *composer require* command from your terminal: |
| 19 | +Install the package via Composer: |
10 | 20 |
|
11 | 21 | ```bash
|
12 | 22 | composer require cleaniquecoders/laravel-expiry
|
13 | 23 | ```
|
14 | 24 |
|
15 |
| -Then publish and run the migration files: |
| 25 | +Publish and run the migration files to add the necessary expiry columns: |
16 | 26 |
|
17 | 27 | ```bash
|
18 | 28 | php artisan vendor:publish --tag=laravel-expiry-migrations
|
19 | 29 | php artisan migrate
|
20 | 30 | ```
|
21 | 31 |
|
22 |
| -Register route middlewares in `app/Http/Kernel.php`: |
| 32 | +### Middleware Registration |
| 33 | + |
| 34 | +The package automatically registers the following middleware in your application: |
| 35 | + |
| 36 | +- **`account.expiry`**: Handles account expiry checks. |
| 37 | +- **`password.expiry`**: Handles password expiry checks. |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## Usage |
| 42 | + |
| 43 | +### Apply Middleware |
| 44 | + |
| 45 | +Use the middleware in your routes to enforce expiry checks: |
23 | 46 |
|
24 | 47 | ```php
|
25 |
| -'account.expiry' => \CleaniqueCoders\LaravelExpiry\Http\Middleware\AccountExpiry::class, |
26 |
| -'password.expiry' => \CleaniqueCoders\LaravelExpiry\Http\Middleware\PasswordExpiry::class, |
| 48 | +Route::middleware(['account.expiry', 'password.expiry'])->group(function () { |
| 49 | + Route::get('/protected-route', [SomeController::class, 'index']); |
| 50 | +}); |
27 | 51 | ```
|
28 | 52 |
|
29 |
| -## Usage |
| 53 | +### Event Listeners |
30 | 54 |
|
31 |
| -Now you may use the middleware in your application: |
| 55 | +The package provides a configuration-driven approach to managing event listeners. By default, the following events and listeners are configured: |
| 56 | + |
| 57 | +#### Default Event-to-Listener Mapping |
| 58 | + |
| 59 | +The configuration (`config/laravel-expiry.php`) includes the following mappings: |
32 | 60 |
|
33 | 61 | ```php
|
34 |
| -Route::middleware(['account.expiry', 'password.expiry']) |
35 |
| - ->get('/somewhere-not-expired'); |
| 62 | +'events' => [ |
| 63 | + \CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount::class => [ |
| 64 | + \CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired::class, |
| 65 | + ], |
| 66 | + \CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword::class => [ |
| 67 | + \CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired::class, |
| 68 | + ], |
| 69 | +], |
36 | 70 | ```
|
37 | 71 |
|
38 |
| -You can listen to the following events on account and password expiry: |
| 72 | +#### Handling Events |
| 73 | + |
| 74 | +The package automatically registers these events and listeners. You can modify or extend the behaviour by updating the configuration file. |
| 75 | + |
| 76 | +For example, when a user's account or password expires: |
| 77 | + |
| 78 | +- The **`ExpiredAccount`** or **`ExpiredPassword`** event is triggered. |
| 79 | +- The **`LogoutOnExpired`** listener handles these events by logging the user out. |
| 80 | + |
| 81 | +#### Customising Listeners |
| 82 | + |
| 83 | +To add custom listeners for these events, update the configuration file (`config/laravel-expiry.php`): |
39 | 84 |
|
40 | 85 | ```php
|
41 |
| -use CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount; |
42 |
| -use CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword; |
| 86 | +'events' => [ |
| 87 | + \CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount::class => [ |
| 88 | + \App\Listeners\YourCustomListener::class, |
| 89 | + ], |
| 90 | + \CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword::class => [ |
| 91 | + \App\Listeners\YourCustomListener::class, |
| 92 | + ], |
| 93 | +], |
43 | 94 | ```
|
44 | 95 |
|
45 |
| -## Test |
| 96 | +With this setup, the package makes it easy to integrate custom logic for handling expiry events. |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## Testing |
46 | 101 |
|
47 |
| -Run the following command: |
| 102 | +To run the test suite, use the following command: |
48 | 103 |
|
49 | 104 | ```bash
|
50 |
| -vendor/bin/phpunit --testdox --verbose |
| 105 | +vendor/bin/pest --testdox |
51 | 106 | ```
|
52 | 107 |
|
| 108 | +The package is fully tested with PestPHP to ensure reliability. |
| 109 | + |
| 110 | +--- |
| 111 | + |
53 | 112 | ## Contributing
|
54 | 113 |
|
55 |
| -Thank you for considering contributing to the `cleaniquecoders/laravel-expiry`! |
| 114 | +Thank you for considering contributing to `cleaniquecoders/laravel-expiry`. Contributions are welcome and appreciated! |
56 | 115 |
|
57 |
| -### Bug Reports |
| 116 | +### Reporting Bugs |
58 | 117 |
|
59 |
| -To encourage active collaboration, it is strongly encourages pull requests, not just bug reports. "Bug reports" may also be sent in the form of a pull request containing a failing test. |
| 118 | +If you find a bug, you can either: |
60 | 119 |
|
61 |
| -However, if you file a bug report, your issue should contain a title and a clear description of the issue. You should also include as much relevant information as possible and a code sample that demonstrates the issue. The goal of a bug report is to make it easy for yourself - and others - to replicate the bug and develop a fix. |
| 120 | +- Submit a pull request with a failing test case. |
| 121 | +- Create an issue describing the problem clearly with steps to reproduce it. |
62 | 122 |
|
63 |
| -Remember, bug reports are created in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the bug report will automatically see any activity or that others will jump to fix it. Creating a bug report serves to help yourself and others start on the path of fixing the problem. |
| 123 | +### Coding Style |
64 | 124 |
|
65 |
| -## Coding Style |
| 125 | +The package follows **PSR-2** coding standards and **PSR-4** autoloading. |
66 | 126 |
|
67 |
| -`cleaniquecoders/laravel-expiry` follows the PSR-2 coding standard and the PSR-4 autoloading standard. |
| 127 | +--- |
68 | 128 |
|
69 | 129 | ## License
|
70 | 130 |
|
71 |
| -This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). |
| 131 | +This package is open-source software licensed under the [MIT license](http://opensource.org/licenses/MIT). |
0 commit comments