From 056783b9324d4cc0cf266961ff7212044b2455f9 Mon Sep 17 00:00:00 2001 From: Pedro X Date: Tue, 29 Aug 2023 17:02:11 +0100 Subject: [PATCH 1/9] add email validation --- 6.x/base-how-to.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index b45739bf..fc9899fc 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -413,3 +413,59 @@ Add whatever validation rules & inputs you want, in addition to name and passwor ``` This will make the registration process pick up a view you can create, in ```resources/views/vendor/backpack/ui/auth/register.blade.php```. You can copy-paste the original view, and modify as you please. Including adding your own custom inputs. + +### Enable email verification in Backpack routes + +In Backpack CRUD 6.2 we introduced the ability to require email verification when accessing Backpack routes. + +To enable this feature please do the following: + +**Step 1** - Ensure your Authenticable model (usually `App\Models\User`) implements the `Illuminate\Contracts\Auth\MustVerifyEmail` contract. + +```php +addColumn('timestamp', 'email_verified_at', ['nullable' => true])->after('email'); + }); + } +}; +``` +More info in: [Preparing database for email verification](https://laravel.com/docs/10.x/verification#database-preparation) + +**Step 3** - Enable the functionality by changing `setup_email_validation_routes` in `config/backpack/base.php` to `true`. + +If you don't have this config there, it's a good time to add it. + + From 528d87a2ff34722ae207d5261478adb816534be0 Mon Sep 17 00:00:00 2001 From: Pedro X Date: Tue, 29 Aug 2023 22:06:56 +0100 Subject: [PATCH 2/9] add alias requirement --- 6.x/base-how-to.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index fc9899fc..828cbfb3 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -464,8 +464,20 @@ return new class() extends Migration { ``` More info in: [Preparing database for email verification](https://laravel.com/docs/10.x/verification#database-preparation) -**Step 3** - Enable the functionality by changing `setup_email_validation_routes` in `config/backpack/base.php` to `true`. +**Step 3** - Make sure you have the `verified` and `signed` middleware alias in your `App\Http\Kernel.php` file. New Laravel 10 installations already have them, but if you came from earlier versions it's possible that they are missing. -If you don't have this config there, it's a good time to add it. +```php +protected $middlewareAliases = [ + // ... other middleware aliases + 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + // if you don't have the VaidateSignature middleware you can copy it from here: + // https://github.com/laravel/laravel/blob/10.x/app/Http/Middleware/ValidateSignature.php + 'signed' => \App\Http\Middleware\ValidateSignature::class, + ]; +``` + +**Step 4** - Enable the functionality by changing `setup_email_validation_routes` in `config/backpack/base.php` to `true`. + +If you don't have this config key there, now it's a good time to add it. From 7f0b612d5761cd15d6bb646f29c5c543dcf829e5 Mon Sep 17 00:00:00 2001 From: Pedro Martins Date: Wed, 30 Aug 2023 11:16:22 +0100 Subject: [PATCH 3/9] Update 6.x/base-how-to.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cristian Tăbăcitu --- 6.x/base-how-to.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index 828cbfb3..4b3a6470 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -476,8 +476,7 @@ protected $middlewareAliases = [ ]; ``` -**Step 4** - Enable the functionality by changing `setup_email_validation_routes` in `config/backpack/base.php` to `true`. +**Step 4** - Enable the functionality in `config/backpack/base.php` by changing `setup_email_validation_routes` to `true`. If you don't have this config key there, now is a good time to add it. -If you don't have this config key there, now it's a good time to add it. From 3491b865ee5525af2885dbaa9f54bf54001af2c9 Mon Sep 17 00:00:00 2001 From: Pedro Martins Date: Thu, 31 Aug 2023 09:02:29 +0100 Subject: [PATCH 4/9] Update 6.x/base-how-to.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cristian Tăbăcitu --- 6.x/base-how-to.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index 4b3a6470..addb8be4 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -453,14 +453,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { - public function up() +return new class extends Migration +{ + /** + * Run the migrations. + */ + public function up(): void { Schema::table('users', function (Blueprint $table) { $table->addColumn('timestamp', 'email_verified_at', ['nullable' => true])->after('email'); }); } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn(['email_verified_at']); + }); + } }; + ``` More info in: [Preparing database for email verification](https://laravel.com/docs/10.x/verification#database-preparation) From 42699a73fde8bada3e01c02d4aa9c60034a78dc8 Mon Sep 17 00:00:00 2001 From: Pedro Martins Date: Thu, 31 Aug 2023 09:02:57 +0100 Subject: [PATCH 5/9] Update 6.x/base-how-to.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cristian Tăbăcitu --- 6.x/base-how-to.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index addb8be4..528a99c4 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -416,9 +416,7 @@ This will make the registration process pick up a view you can create, in ```res ### Enable email verification in Backpack routes -In Backpack CRUD 6.2 we introduced the ability to require email verification when accessing Backpack routes. - -To enable this feature please do the following: +In Backpack CRUD 6.2 we introduced the ability to require email verification when accessing Backpack routes. To enable this feature please do the following: **Step 1** - Ensure your Authenticable model (usually `App\Models\User`) implements the `Illuminate\Contracts\Auth\MustVerifyEmail` contract. From 79b768550a4e7e858debc5d36a34a0148bbf535a Mon Sep 17 00:00:00 2001 From: Pedro Martins Date: Thu, 31 Aug 2023 09:03:43 +0100 Subject: [PATCH 6/9] Update 6.x/base-how-to.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cristian Tăbăcitu --- 6.x/base-how-to.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index 528a99c4..549ed190 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -418,7 +418,7 @@ This will make the registration process pick up a view you can create, in ```res In Backpack CRUD 6.2 we introduced the ability to require email verification when accessing Backpack routes. To enable this feature please do the following: -**Step 1** - Ensure your Authenticable model (usually `App\Models\User`) implements the `Illuminate\Contracts\Auth\MustVerifyEmail` contract. +**Step 1** - Make sure your user model (usually `App\Models\User`) implements the `Illuminate\Contracts\Auth\MustVerifyEmail` contract. [More info](https://laravel.com/docs/10.x/verification#model-preparation). ```php Date: Thu, 31 Aug 2023 09:50:28 +0100 Subject: [PATCH 7/9] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cristian Tăbăcitu --- 6.x/base-how-to.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index 549ed190..a1187304 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -438,11 +438,9 @@ class User extends Authenticatable implements MustVerifyEmail ``` More info in: [Preparing model for email verification](https://laravel.com/docs/10.x/verification#model-preparation) -**Step 2** - Make sure your Authenticable model table has a `email_verified_at`timestamp column. +**Step 2** - Make sure your user model table has a `email_verified_at` column (timestamp). New Laravel installations already have it, but if you upgraded from L8/L9 it's possible that the `email_verified_at` column is missing. -New Laravel instalations already bring this column, but if you came from earlier versions it's possible that `email_verified_at` column is missing. - -You can quickly create a new migration that add that column with the following code: (please adjust table name if different from default). +You can quickly create a new migration using `php artisan make:migration add_email_verified_at_column_to_users --table=users`, then use the code below: ```php Date: Thu, 31 Aug 2023 09:51:12 +0100 Subject: [PATCH 8/9] Update 6.x/base-how-to.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cristian Tăbăcitu --- 6.x/base-how-to.md | 1 - 1 file changed, 1 deletion(-) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index a1187304..3ea894d2 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -436,7 +436,6 @@ class User extends Authenticatable implements MustVerifyEmail // ... } ``` -More info in: [Preparing model for email verification](https://laravel.com/docs/10.x/verification#model-preparation) **Step 2** - Make sure your user model table has a `email_verified_at` column (timestamp). New Laravel installations already have it, but if you upgraded from L8/L9 it's possible that the `email_verified_at` column is missing. From 17f173d9fb77dd30323b41cb7c42a6e1d06e1885 Mon Sep 17 00:00:00 2001 From: Pedro Martins Date: Thu, 31 Aug 2023 09:52:31 +0100 Subject: [PATCH 9/9] Update 6.x/base-how-to.md --- 6.x/base-how-to.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/6.x/base-how-to.md b/6.x/base-how-to.md index 3ea894d2..fbdbea86 100644 --- a/6.x/base-how-to.md +++ b/6.x/base-how-to.md @@ -472,7 +472,7 @@ return new class extends Migration }; ``` -Then run `php artisan migrate`. [More info](https://laravel.com/docs/10.x/verification#database-preparation).More info in: [Preparing database for email verification](https://laravel.com/docs/10.x/verification#database-preparation) +Then run `php artisan migrate`. [More info](https://laravel.com/docs/10.x/verification#database-preparation). **Step 3** - Make sure you have the `verified` and `signed` middleware alias in your `App\Http\Kernel.php` file. New Laravel 10 installations already have them, but if you came from earlier versions it's possible that they are missing.