2017 © Pedro Peláez
 

library verifi

A Laravel package to handle email verification.

image

selim-salihovic/verifi

A Laravel package to handle email verification.

  • Tuesday, May 30, 2017
  • by SelimSalihovic
  • Repository
  • 1 Watchers
  • 1 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Laravel Verifi

Travis Packagist Packagist Packagist, (*1)

A Laravel package to handle email verification., (*2)

It is inspired by crypto-based password resets and the email verification package by josiasmontag., (*3)

  • Crypto-based email verification. No need to store a temporary token in the database!
  • Event-based totally. No need to override your register() method.
  • Using the Laravel 5.4 notification system.
  • You're free to create routes anyway you like.
  • Resend the verification email anytime.
  • Customize the email notification.

Installation

Install this package via Composer., (*4)

composer require meness/verifi

You must install both the service provider and the facade., (*5)

'providers' => [
    ...
    Meness\Verifi\Providers\VerifiServiceProvider::class,
];

'aliases' => [
    ...
    'Verifi' => Meness\Verifi\Facades\Verifi::class,
];

A migration is provided to add a is_email_verified column to the existing users table, you can publish the migration., (*6)

php artisan vendor:publish --provider="Meness\Verifi\Providers\VerifiServiceProvider" --tag="migrations"

Remember to run the following command if you published the migration., (*7)

php artisan migrate

A configuration file is also provided, you can publish the configuration., (*8)

php artisan vendor:publish --provider="Meness\Verifi\Providers\VerifiServiceProvider" --tag="config"

Configuration

expiration

1440 (in minutes, 24 hours) set by default., (*9)

verify_route

/verify set by default. Change the value if you're using a different route for verification., (*10)

send_notifications

true set by default. Let this package send an email notification automatically after the registration complete., (*11)

How to Use (Step by Step)

Step One

  1. The User model must implement Meness\Verifi\Entities\Traits\Contracts\Verifi interface., (*12)

  2. Add Meness\Verifi\Entities\Traits\VerifiTrait as a trait if you're going to use the default notification., (*13)

class User extends Authenticatable implements Verifi
{
    use Notifiable, VerifiTrait;
}

Note: Some methods are not implemented, you must do it yourself., (*14)

Step Two

You're free to create routes, because there're no default routes provided with this package., (*15)

Route::get('/verify', 'Auth\RegisterController@verify');
Route::get('/resend', 'Auth\RegisterController@resend');

Note: Remember to change the verify_route value if you're not going to use the default route., (*16)

Step Three (Optional)

Create listeners for necessary events. There're three events provided with this package: InvalidCredentials, VerificationSent, and Verified., (*17)

Step Four

There're two methods available, verify() and resend()., (*18)

Note: An email verification will be sent after the registration complete if send_notifications set true, so you're not required to do it manually., (*19)

verify()

Verifi::verify() expects a request object and an optional callback. It verifies credentials provided with the request., (*20)

Verifi::verify(request(), function ($user) {

    if (is_null($user)) {
        // Invalid credentials provided
    } else {
        // Verified
    }
});

resend()

Verifi::resend() expects an user model object and an optional callback. It sends the verification email to the provided user., (*21)

Verifi::resend($user, function ($user) {
    // Resent successfully
});

Step Five (Optional)

There's a middleware called IsEmailVerified to determine if the user's email address is verified., (*22)

$routeMiddleware = [
    ...
    'isEmailVerified' => \Meness\Verifi\Http\Middleware\IsEmailVerified::class,
];

Changelog

Please see releases for more information what has changed recently., (*23)

Contributing

Please see CONTRIBUTING for details., (*24)

Credits

License

Verifi is open-sourced software licensed under the MIT license., (*25)

The Versions