diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..02cb13c --- /dev/null +++ b/TODO.md @@ -0,0 +1,10 @@ +# Email Verification Implementation TODO + +- [x] Enable MustVerifyEmail trait in app/Models/User.php +- [x] Add email verification routes to routes/web.php +- [x] Modify RegisteredUserController to remove auto-login and redirect to verification notice +- [x] Update AuthenticatedSessionController to check verification on login +- [x] Modify welcome email template to include verification link +- [x] Create verify-email.blade.php view +- [x] Apply 'verified' middleware to protected routes +- [x] Test the registration and verification flow diff --git a/app/Http/Controllers/Auth/AuthenticatedSessionController.php b/app/Http/Controllers/Auth/AuthenticatedSessionController.php index 102966a..e798b3c 100644 --- a/app/Http/Controllers/Auth/AuthenticatedSessionController.php +++ b/app/Http/Controllers/Auth/AuthenticatedSessionController.php @@ -34,6 +34,13 @@ class AuthenticatedSessionController extends Controller if (Auth::attempt($credentials)) { $request->session()->regenerate(); + if (!$request->user()->hasVerifiedEmail()) { + Auth::logout(); + return redirect()->route('verification.notice')->withErrors([ + 'email' => 'You need to verify your email address before logging in.', + ]); + } + return redirect()->route('family.dashboard'); } diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 1d64a8d..cd60f18 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -61,8 +61,6 @@ class RegisteredUserController extends Controller // Send welcome email Mail::to($user->email)->send(new WelcomeEmail($user, $user, null)); - Auth::login($user); - - return redirect()->route('login')->with('success', 'Registration successful! Please login with your credentials.'); + return redirect()->route('verification.notice')->with('success', 'Registration successful! Please check your email to verify your account.'); } } diff --git a/app/Models/User.php b/app/Models/User.php index 37b488f..bcd3984 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,6 +3,7 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -14,7 +15,7 @@ use Carbon\Carbon; class User extends Authenticatable { /** @use HasFactory<\Database\Factories\UserFactory> */ - use HasFactory, Notifiable; + use HasFactory, Notifiable, MustVerifyEmail; /** * The attributes that are mass assignable. diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 62ece77..1819fd3 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -42,7 +42,7 @@
-

Create Your Profile

+

Register

@@ -178,7 +178,7 @@
diff --git a/resources/views/auth/verify-email.blade.php b/resources/views/auth/verify-email.blade.php new file mode 100644 index 0000000..00a75fd --- /dev/null +++ b/resources/views/auth/verify-email.blade.php @@ -0,0 +1,55 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
+
+

Verify Your Email

+

We've sent a verification link to your email address.

+
+ + @if (session('resent')) + + @endif + + @if (session('verified')) + + @endif + +

+ Before proceeding, please check your email for a verification link. + If you did not receive the email, we will gladly send you another. +

+ +
+ @csrf + +
+ +
+
+ +
+ + Logout + + +
+ @csrf +
+
+
+
+
+
+
+@endsection diff --git a/resources/views/components/country-code-dropdown.blade.php b/resources/views/components/country-code-dropdown.blade.php index 726846c..e0c70a7 100644 --- a/resources/views/components/country-code-dropdown.blade.php +++ b/resources/views/components/country-code-dropdown.blade.php @@ -1,20 +1,26 @@ @props(['name' => 'country_code', 'id' => 'country_code', 'value' => '+1', 'required' => false, 'error' => null]) -
+
-