User activation for Laravel 5.2
, (*1)
This package implements a simple user verification by email by means of a random token, aka "Activation Code"., (*2)
Description
The purpose of this package is to take advantage of Laravel's native Registration and Authentication features, by simply
running php artisan make:auth and avoid the hassle of writing any aditional routes, controllers and/or views., (*3)
Once installed and configured, it will observe the :created event on the user provider model. As soon as a User is created,
it will trigger the service provider that will handle the activation process: token creation, sending an activation email,
and storage., (*4)
The newly registered user will be unable to login, unless a request is made with the proper unique token (activation link)., (*5)
We will then check if the request is "legit", and, if required by the configuration settings, it's lifetime., (*6)
Uniqueness of token is ensured by a random sha256 hash (64 char long)., (*7)
The user will have the ability to request a new token, in the login form, as long as valid credentials
(those used upon registration) are provided; Just in case the user lost his token,
for whatever reason. He who never accidentally deleted an email..., (*8)
The site admin also has an option to receive email notifications of such events:
user registered, user activated, and user requested a new token., (*9)
All email outputs are queued, for improved performance., (*10)
Requirements
-Laravel >= 5.2.X
-PHP >= 5.6
Installation
After creating your Authentication routes and views with php artisan make:auth proceed with installation:, (*11)
1 - Require with Composer: composer require samkitano/laravel-user-activation, (*12)
2 - Include the service provider in the 'providers' array within config/app.php., (*13)
'providers' => [
Kitano\UserActivation\UserActivationServiceProvider::class,
];
3 - Publish the package. MUST use the --force option in order to replace default views. Those will be the exact same thing, with just a small session check added., (*14)
php artisan vendor:publish --force
4 - Run migrations:, (*15)
php artisan migrate
5 - Import and Replace Traits in app\Http\Controllers\Auth\AuthController.php, (*16)
<?php
namespace App\Http\Controllers\Auth;
use Kitano\UserActivation\Traits\ActivatesUsers;
//...
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
// Comment or replace this line:
// use AuthenticatesAndRegistersUsers, ThrottlesLogins, ActivatesUsers;
// with:
use ThrottlesLogins, ActivatesUsers;
// ...
6 - Include attribute 'active' in the $fillable array of your User model., (*17)
7 - Check out app\config\user_activation.php to set your own defaults (email address, token lifetime,
templates, etc.), and that's it., (*18)
DON'T FORGET to configure your mail provider in app\config\mail.php. Otherwise, no emails will be sent whatsoever.
Please check out Laravel Mail Documentation for that matter., (*19)
Of course, you may want to change the packages's views and email templates, or even the translation file to suit your needs. Feel free to do so., (*20)
NOTE - Although not tested, the package should work fine with any user provider other than App\User::class,
as long as you add an 'active', boolean, default to 0 field to your users table, and include that attribute in the $fillable
array of your model., (*21)
License
LaravelUserActivation is open-sourced software licensed under the MIT license., (*22)