ahmedash95 / users-verification by ahmedash95

Laravel Package for managing users verification.
19
4
2
Package Data
Maintainer Username: ahmedash95
Maintainer Contact: ahmed29329@gmail.com (Ahmed Ashraf)
Package Create Date: 2017-06-20
Package Last Update: 2017-06-20
Language: PHP
License: MIT
Last Refreshed: 2024-12-15 15:08:41
Package Statistics
Total Downloads: 19
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 4
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel Users Verification

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.