├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── config └── emailverification.php ├── database └── migrations │ └── 2017_02_27_170020_add_verified_to_user_table.php ├── phpunit.xml ├── resources ├── lang │ ├── de │ │ └── messages.php │ ├── en │ │ └── messages.php │ └── nb │ │ └── messages.php └── views │ └── resend.blade.php ├── src ├── Contracts │ └── CanVerifyEmail.php ├── EmailVerification.php ├── Events │ ├── EmailVerificationSent.php │ └── UserVerified.php ├── Exceptions │ └── UserNotVerifiedException.php ├── Http │ └── routes.php ├── Listeners │ └── SendUserVerificationMail.php ├── Middleware │ └── IsEmailVerified.php ├── Notifications │ └── EmailVerification.php ├── Providers │ ├── EmailVerificationEventServiceProvider.php │ └── EmailVerificationServiceProvider.php └── Traits │ ├── CanVerifyEmail.php │ └── VerifiesEmail.php └── tests ├── Feature ├── MiddlewareTest.php ├── RegisterController.php ├── RegistrationTest.php ├── ResendVerificationMailTest.php ├── TestCase.php └── User.php └── Unit └── EmailVerificationTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | .DS_Store 4 | .idea 5 | .project -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.1 5 | - 7.2 6 | - 7.3 7 | 8 | sudo: false 9 | 10 | install: travis_retry composer install --no-interaction --prefer-dist --no-suggest 11 | 12 | script: vendor/bin/phpunit --verbose 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Josias Montag 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
7 | 8 | > ⚠️ **Deprecation Warning**: This package is deprecated. I recommend using Laravel's [built in email verification](https://laravel.com/docs/5.8/verification). 9 | 10 | ## Introduction 11 | 12 | The Laravel Email Verification package is built for Laravel 5.4 and later to easily handle a user verification and validate the e-mail. It is inspired by [crypto-based password resets](https://github.com/laravel/framework/pull/17499) and the [email verification package by jrean](https://github.com/jrean/laravel-user-verification). 13 | 14 | - [x] Crypto-based email verification. No need to store a temporary token in the database! 15 | - [x] Event based: No need to override your `register()` method. 16 | - [x] Using the Laravel 5.3 notification system. 17 | - [x] Allow certain routes for verified users only using the `IsEmailVerified` middleware. 18 | - [x] Let the users resend the verification email at anytime. 19 | - [x] Ready for Localization. 20 | 21 | 22 | ## Configuration 23 | 24 | 25 | To get started, use Composer to add the package to your project's dependencies: 26 | 27 | composer require josiasmontag/laravel-email-verification 28 | 29 | 30 | In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just register the `Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider` in your `config/app.php` configuration file: 31 | 32 | ```php 33 | 'providers' => [ 34 | // Other service providers... 35 | 36 | Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider::class, 37 | ], 38 | ``` 39 | 40 | ### Migration 41 | 42 | The table representing the user must be updated with a `verified` column. 43 | This update will be performed by the migrations included with this package. 44 | 45 | To run the migrations from this package use the following command: 46 | 47 | ``` 48 | php artisan migrate --path="/vendor/josiasmontag/laravel-email-verification/database/migrations" 49 | ``` 50 | 51 | The package tries to guess your `user` table by checking what is set in the auth providers users settings. 52 | If this key is not found, the default `App\User` will be used to get the table name. 53 | 54 | To customize the migration, publish it with the following command: 55 | 56 | ``` 57 | php artisan vendor:publish --provider="Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider" --tag="migrations" 58 | ``` 59 | 60 | ### User Model 61 | 62 | The model representing the `User` must implement the `CanVerifyEmail` interface. The package comes with a `CanVerifyEmail` trait for a quick implementation. You can customize this trait in order to change the activation email. 63 | 64 | 65 | ```php 66 | use Illuminate\Foundation\Auth\User as Authenticatable; 67 | use Lunaweb\EmailVerification\Traits\CanVerifyEmail; 68 | use Lunaweb\EmailVerification\Contracts\CanVerifyEmail as CanVerifyEmailContract; 69 | 70 | class User extends Authenticatable implements CanVerifyEmailContract 71 | { 72 | 73 | use CanVerifyEmail; 74 | 75 | // ... 76 | } 77 | ``` 78 | 79 | ### Register Controller 80 | 81 | The package offers a `VerifiesEmail` trait for your `RegisterController`. You must update the middleware exception to allow `verify` routes to be access by authenticated users. 82 | 83 | ```php 84 | 85 | use Lunaweb\EmailVerification\Traits\VerifiesEmail; 86 | 87 | class RegisterController extends Controller 88 | { 89 | 90 | use RegistersUsers, VerifiesEmail; 91 | 92 | 93 | public function __construct() 94 | { 95 | $this->middleware('guest', ['except' => ['verify', 'showResendVerificationEmailForm', 'resendVerificationEmail']]); 96 | $this->middleware('auth', ['only' => ['showResendVerificationEmailForm', 'resendVerificationEmail']]); 97 | } 98 | 99 | // ... 100 | 101 | } 102 | 103 | ``` 104 | 105 | There is no need to override `register()`. As default, the package listens for the `Illuminate\Auth\Events\Registered` event and sends the verification mail. You can disable this behavior using the `listen_registered_event` setting. 106 | 107 | ### Routes 108 | 109 | The package adds the following routes. 110 | 111 | ```php 112 | Route::get('register/verify', 'App\Http\Controllers\Auth\RegisterController@verify')->name('verifyEmailLink'); 113 | Route::get('register/verify/resend', 'App\Http\Controllers\Auth\RegisterController@showResendVerificationEmailForm')->name('showResendVerificationEmailForm'); 114 | Route::post('register/verify/resend', 'App\Http\Controllers\Auth\RegisterController@resendVerificationEmail')->name('resendVerificationEmail'); 115 | 116 | ``` 117 | 118 | ### Middleware 119 | 120 | 121 | To register the IsEmailVerified middleware add the following to the `$routeMiddleware` array within the `app/Http/Kernel.php` file: 122 | 123 | ```php 124 | protected $routeMiddleware = [ 125 | // … 126 | 'isEmailVerified' => \Lunaweb\EmailVerification\Middleware\IsEmailVerified::class, 127 | ``` 128 | 129 | Apply the middleware on your routes: 130 | 131 | ```php 132 | Route::group(['middleware' => ['web', 'auth', 'isEmailVerified']], function () { 133 | … 134 | ``` 135 | 136 | ### Events 137 | 138 | The package emits 2 events: 139 | 140 | * ``Lunaweb\EmailVerification\Events\EmailVerificationSent`` 141 | * ``Lunaweb\EmailVerification\Events\UserVerified`` 142 | 143 | 144 | 145 | ### Resend the verification mail 146 | 147 | Using the `isEmailVerified` Middleware, the following form is shown to the user. It allows the user to correct his email address and resend the verification mail. 148 | 149 |  150 | 151 | You can manually point the user to this form using the `showResendVerificationEmailForm` route (Default: `register/verify/resend`). 152 | 153 | To programmatically resend the verification mail: 154 | ```php 155 | $this->app->make('Lunaweb\EmailVerification\EmailVerification')->sendVerifyLink($user); 156 | ``` 157 | 158 | 159 | ### Customize the verification mail 160 | 161 | Therefore, override `sendEmailVerificationNotification()` of your User model. Example: 162 | 163 | ```php 164 | class User implements CanVerifyEmailContract 165 | { 166 | 167 | use CanVerifyEmail; 168 | 169 | /** 170 | * Send the email verification notification. 171 | * 172 | * @param string $token The verification mail reset token. 173 | * @param int $expiration The verification mail expiration date. 174 | * @return void 175 | */ 176 | public function sendEmailVerificationNotification($token, $expiration) 177 | { 178 | $this->notify(new MyEmailVerificationNotification($token, $expiration)); 179 | } 180 | } 181 | ``` 182 | 183 | ### Customize the resend form 184 | ``` 185 | php artisan vendor:publish --provider="Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider" --tag="views" 186 | ``` 187 | The template can be found in `resources/views/vendor/emailverification/resend.blade.php` 188 | 189 | ### Customize the messages / localization 190 | ``` 191 | php artisan vendor:publish --provider="Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider" --tag="translations" 192 | ``` 193 | The localization files can be found in `resources/lang/vendor/emailverification` 194 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "josiasmontag/laravel-email-verification", 3 | "description": "Laravel Email Verification", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Josias Montag", 8 | "email": "josias@montag.info" 9 | } 10 | ], 11 | "require": { 12 | "php": ">=7.1.0", 13 | "illuminate/support": "5.4.*|5.5.*|5.6.*|5.7.*|5.8.*", 14 | "illuminate/queue": "5.4.*|5.5.*|5.6.*|5.7.*|5.8.*", 15 | "illuminate/auth": "5.4.*|5.5.*|5.6.*|5.7.*|5.8.*", 16 | "nesbot/carbon": "^1.20|2.0" 17 | }, 18 | "require-dev": { 19 | "mockery/mockery": "1.2", 20 | "phpunit/phpunit": "^5.7|6.2|^7.0", 21 | "orchestra/testbench": "~3.4.0|^3.5.0|^3.6.0|^3.7.0|^3.8.0", 22 | "laravel/framework": "5.4.*|5.5.*|5.6.*|5.7.*|5.8.*" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "Lunaweb\\EmailVerification\\": "src/" 27 | } 28 | }, 29 | "autoload-dev": { 30 | "psr-4": { 31 | "Lunaweb\\EmailVerification\\Tests\\": "tests/" 32 | } 33 | }, 34 | "config": { 35 | "sort-packages": true 36 | }, 37 | "prefer-stable": true, 38 | "minimum-stability": "dev", 39 | "extra": { 40 | "laravel": { 41 | "providers": [ 42 | "Lunaweb\\EmailVerification\\Providers\\EmailVerificationServiceProvider" 43 | ] 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /config/emailverification.php: -------------------------------------------------------------------------------- 1 | 1440, 11 | 12 | /** 13 | * Whether to listen to the \Illuminate\Auth\Events\Registered event to automatically 14 | * send a verification email. 15 | * Disable it to trigger the verification manually. 16 | */ 17 | 18 | "listen_registered_event" => true 19 | 20 | ]; -------------------------------------------------------------------------------- /database/migrations/2017_02_27_170020_add_verified_to_user_table.php: -------------------------------------------------------------------------------- 1 | getTable(); 24 | } 25 | 26 | /** 27 | * Run the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function up() 32 | { 33 | Schema::table($this->getUserTableName(), function (Blueprint $table) { 34 | $table->boolean('verified')->default(false); 35 | }); 36 | 37 | } 38 | 39 | /** 40 | * Reverse the migrations. 41 | * 42 | * @return void 43 | */ 44 | public function down() 45 | { 46 | Schema::table($this->getUserTableName(), function (Blueprint $table) { 47 | $table->dropColumn('verified'); 48 | }); 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 |