ahmedash95 / users-verification
Laravel Package for managing users verification.
This package is auto-updated.
Last update: 2024-11-04 11:47:52 UTC
README
This package contains a trait to support Eloquent Models Verification
$user = App\User::find(1); // Generate token or get it if exists $user->getToken(); // check if user is verified or not $user->isVerified() // check if token is valid for user $token = 'random_token_generated_by_getToken()_method' $user->verifyToken($token) // return true or false // verify the user if($user->verifyToken($token)) { $user->verify(); } // remove user token $user->flushToken();
Installation
You can install the package via composer:
composer require ahmedash95/users-verification
Next up, the service provider must be registered:
// config/app.php 'providers' => [ ... Ahmedash95\UsersVerification\UsersVerificationServiceProvider::class, ];
you must publish the migration file:
php artisan vendor:publish --provider="Ahmedash95\UsersVerification\UsersVerificationServiceProvider" --tag="migrations"
then run the migration command
php artisan migrate
Use verification in User model
use Illuminate\Foundation\Auth\User as Authenticatable; use Ahmedash95\UsersVerification\UsersVerification; class User extends Authenticatable { use UsersVerification;
Available Methods
Get\Generate token for user
The getToken
method will return the user token string or generate it if it doesn't not exists.
public function getToken() : string
Check user token
This method will verify if the given token is valid for the user
public function verifyToken(String $token) : bool
Verify the user
After checking if the token is valid you may want to activate user verification .. then you should use verify
method
public function verify()
Get user by token
If you want to validate your users using token you could use findByToken
method
public static function findByToken($token)
this method return object of user or null if doesn't exists
Remove user's token
public function flushToken()
Security
If you discover any security related issues, please email ahmed29329@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.