wijourdil / laravel-account-lock
This package helps you to easily lock users accounts via links in emails.
Fund package maintenance!
wijourdil
Requires
- php: ^8.0
- illuminate/contracts: ^8.37
- spatie/laravel-package-tools: ^1.4.3
- thecodingmachine/safe: ^1.3
Requires (Dev)
- brianium/paratest: ^6.2
- nunomaduro/collision: ^5.3
- nunomaduro/larastan: ^0.7.10
- orchestra/testbench: ^6.15
- phpunit/phpunit: ^9.3
- thecodingmachine/phpstan-safe-rule: ^1.0
README
This package helps you to easily lock users accounts via links in emails.
Requirements & Compatibility
- PHP ^8.0
- Laravel 8
Installation
You can install the package via composer:
composer require wijourdil/laravel-account-lock
Publish all the files (config, migrations, translations, views) with:
php artisan vendor:publish --provider="Wijourdil\LaravelAccountLock\LaravelAccountLockServiceProvider"
Then run the migrations with:
php artisan migrate
Configuration & Customization
Configuration file
See the published config file config/account-lock.php
to customize available configuration.
Blade templates
See the published files in the folder resources/views/vendor/account-lock
To customize the page displayed to a user when he locks successfully his account, you can edit this
file: account-locked.blade.php
ℹ️ It is recommended to check the mail
variable used in the published template
Strings translations
See the published files in the folder resources/lang/vendor/account-lock
Usage
Apply the middleware to your routes
This package comes with a middleware returning a 403 HTTP status if the current authenticated user tries to access a protected route.
Use the account-not-locked
middleware on the routes you want to protect:
Route::middleware('account-not-locked')->group(function () { // Your routes here });
Use the service class
If you want to use the service class, you can either instantiate it yourself or use it like a Facade, depending on your preferences.
If you want to instantiate the service / use dependency injection, you must import the class:
use Wijourdil\LaravelAccountLock\AccountLock; $url = (new AccountLock)->generateLockUrl(...);
If you want to use it like a Facade, you just have to call the methods without importing nothing, like:
$url = AccountLock::generateLockUrl(...);
Available methods
Generate an URL to lock account
$user = Auth::user(); $expirationInMinutes = 60 * 24 * 7; // 1 week $lockUrl = AccountLock::generateLockUrl($user, $expirationInMinutes);
Manually lock an account
$user = Auth::user(); AccountLock::lock($user);
Manually unlock an account
$user = Auth::user(); AccountLock::unlock($user);
Check if an account is locked
$user = Auth::user(); AccountLock::isLocked($user);
Testing
Run the tests without code coverage:
composer test
Run the tests with code coverage:
composer test-coverage
Run phpstan code analysis:
composer stan
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.