Codepunk Activatinator
Introduction
Codepunk Activatinator is an extension of Laravel's Auth framework that
requires users to activate their account via email (or other notification) before
being allowed to view any content normally visible to authenticated users., (*1)
Activatinator mimics the logic and extendability of the Laravel Auth "Password Reset"
functionality. See Laravel's Authentication
and Resetting Passwords pages for more information.
Many of the customizations provided by Laravel when it comes to resetting passwords
are also provided by the Activatinator., (*2)
What's with the name?
The over-syllabic "Activatinator" is a shout-out to Heinz Doofenshmirtz, the villain
in the "Phineas and Ferb" cartoon series. According to the
Phineas and Ferb Wiki,
"Doofenshmirtz's schemes and inventions, primarily known as 'Inators,' are plans and
devices created by Dr. Heinz Doofenshmirtz as a means of dominating and taking over
the Tri-State Area or other locations.", (*3)
Since coding can often times feel like hatching a brilliant (and sometimes evil)
scheme to take over the world, Codepunk borrows Doofenshmirtz's "Inator"-style naming
convention., (*4)
Install
-
If you haven't already done so:, (*5)
-
Create a new Laravel project:, (*6)
$ laravel new my_project
-
Update your .env
file to point to a valid database and email client., (*7)
-
From within your new project directory, set up the Laravel authentication framework:, (*8)
$ php artisan make:auth
-
Require the Codepunk Activatinator!, (*9)
-
Via Composer:, (*10)
bash
$ composer require codepunk/activatinator
, (*11)
-
Manually:, (*12)
In the require
section of your project's `composer.json' file, add the following:, (*13)
bash
"codepunk/activatinator": "^1.2.1"
, (*14)
(Or whatever the latest version happens to be), (*15)
Then, update your project by executing the following command:, (*16)
bash
$ composer update
, (*17)
-
Publish the Activatinator package:, (*18)
$ php artisan vendor:publish --force
And choose the Codepunk ActivatinatorServiceProvider option., (*19)
-
Update the database with the required changes:, (*20)
$ php artisan migrate:refresh
- Make changes to your
App\User
model:
-
Add the following use
statements:, (*21)
php
use Codepunk\Activatinator\Activable;
use Codepunk\Activatinator\Contracts\Activable as ActivableContract;
, (*22)
-
Update the following:, (*23)
php
class User extends Authenticatable
, (*24)
to this:, (*25)
php
class User extends Authenticatable
implements ActivableContract
, (*26)
-
Update the following:, (*27)
php
use Notifiable;
, (*28)
to this:, (*29)
php
use Notifiable, Activable;
, (*30)
-
NOTE: If you are also using Laravel Passport to implement OAuth in your application, then we want the oauth\token
endpoint to fail when the user has not yet been authenticated. To implement this behavior, add the Codepunk\Activatinator\Traits\ValidatesForPassport
trait to your App\User
model (in addition to Passport's HasApiTokens
trait as described in the Laravel Passport documentation):, (*31)
php
use Notifiable, Activable, HasApiTokens, ValidatesForPassport;
, (*32)
-
Make changes to app/Http/Controllers/Auth/ForgotPasswordController.php
:, (*33)
Update the following:, (*34)
php
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
, (*35)
to this:, (*36)
php
use Codepunk\Activatinator\SendsPasswordResetEmails;
, (*37)
-
Make changes to app/Http/Controllers/Auth/LoginController.php
:, (*38)
Update the following:, (*39)
php
use Illuminate\Foundation\Auth\AuthenticatesUsers;
, (*40)
to this:, (*41)
php
use Codepunk\Activatinator\AuthenticatesUsers;
, (*42)
-
Make changes to app/Http/Controllers/Auth/RegisterController.php
:, (*43)
Update the following:, (*44)
php
use Illuminate\Foundation\Auth\RegistersUsers;
, (*45)
to this:, (*46)
php
use Codepunk\Activatinator\RegistersUsers;
, (*47)
-
Make changes to resources/views/auth/login.blade.php
:, (*48)
Find these lines:, (*49)
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
And add the following line in between so it looks like this:, (*50)
<div class="card-body">
@include('codepunk::activatinator-alerts')
<form method="POST" action="{{ route('login') }}">
License
Codepunk Activatinator is open-sourced software licensed under the
MIT license, (*51)