From 1d3e76918834dcd2bb42d1d9e1c0dc4955899ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Wed, 11 Sep 2024 13:47:59 +0100 Subject: [PATCH] wip --- ...mailVerificationNotificationController.php | 15 +- .../Auth/VerifyEmailController.php | 11 +- app/Http/Resources/UserResource.php | 2 + app/Models/User.php | 5 +- app/Providers/AuthServiceProvider.php | 13 ++ lang/ro.json | 3 + resources/js/Components/Alert.vue | 6 +- .../js/Components/EmailVerifiedAlert.vue | 38 ++++ resources/js/Layouts/DefaultLayout.vue | 12 +- resources/js/Layouts/MapLayout.vue | 2 - resources/js/Pages/Account/Dashboard.vue | 198 +++++++++--------- resources/js/Pages/Account/Settings.vue | 41 ++-- resources/js/Pages/Home.vue | 1 - resources/js/app.js | 11 +- routes/auth.php | 6 +- routes/web.php | 2 +- 16 files changed, 209 insertions(+), 157 deletions(-) create mode 100644 resources/js/Components/EmailVerifiedAlert.vue diff --git a/app/Http/Controllers/Auth/EmailVerificationNotificationController.php b/app/Http/Controllers/Auth/EmailVerificationNotificationController.php index d6af5426..3c6458b1 100644 --- a/app/Http/Controllers/Auth/EmailVerificationNotificationController.php +++ b/app/Http/Controllers/Auth/EmailVerificationNotificationController.php @@ -5,26 +5,23 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; -use Illuminate\Http\RedirectResponse; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Inertia\Inertia; -use Inertia\Response; +use Illuminate\Http\Response; class EmailVerificationNotificationController extends Controller { /** * Send a new email verification notification. */ - public function __invoke(Request $request): RedirectResponse|Response + public function __invoke(Request $request): JsonResponse { if ($request->user()->hasVerifiedEmail()) { - return redirect()->intended(); + return response()->json(['message' => 'already-verified'], Response::HTTP_BAD_REQUEST); } - return Inertia::render('Auth/VerifyEmail', [ - 'status' => session('status'), - ]); + $request->user()->sendEmailVerificationNotification(); - // $request->user()->sendEmailVerificationNotification(); + return response()->json(['message' => 'verification-link-sent']); } } diff --git a/app/Http/Controllers/Auth/VerifyEmailController.php b/app/Http/Controllers/Auth/VerifyEmailController.php index 33cbed4e..609edb60 100644 --- a/app/Http/Controllers/Auth/VerifyEmailController.php +++ b/app/Http/Controllers/Auth/VerifyEmailController.php @@ -1,8 +1,11 @@ user()->hasVerifiedEmail()) { - return redirect()->intended( - config('app.frontend_url').'/dashboard?verified=1' - ); + return redirect()->intended(RouteServiceProvider::getDashboardUrl() . '?verified=1'); } if ($request->user()->markEmailAsVerified()) { event(new Verified($request->user())); } - return redirect()->intended( - config('app.frontend_url').'/dashboard?verified=1' - ); + return redirect()->intended(RouteServiceProvider::getDashboardUrl() . '?verified=1'); } } diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index 024c1316..a6a7493b 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -24,6 +24,8 @@ public function toArray(Request $request): array 'phone' => $this->phone, 'avatar' => $this->getFilamentAvatarUrl(), 'created_at' => $this->created_at->isoFormat('Do MMMM YYYY'), + 'is_unverified' => ! $this->hasVerifiedEmail(), + 'show_verified_message' => $request->boolean('verified'), ]; } } diff --git a/app/Models/User.php b/app/Models/User.php index 31218147..b530477e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -11,8 +11,8 @@ use Filament\Models\Contracts\HasAvatar; use Filament\Models\Contracts\HasName; use Filament\Panel; -use Illuminate\Auth\MustVerifyEmail; use Illuminate\Contracts\Auth\CanResetPassword; +use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -25,10 +25,9 @@ use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\Permission\Traits\HasRoles; -class User extends Authenticatable implements FilamentUser, HasAvatar, HasName, HasMedia, CanResetPassword +class User extends Authenticatable implements FilamentUser, HasAvatar, HasName, HasMedia, CanResetPassword, MustVerifyEmail { use InteractsWithMedia; - use MustVerifyEmail; use HasFactory; use Notifiable; use HasRoles; diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 00e865ef..ab6c626c 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -7,7 +7,9 @@ // use Illuminate\Support\Facades\Gate; use Illuminate\Auth\Notifications\ResetPassword; +use Illuminate\Auth\Notifications\VerifyEmail; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; +use Illuminate\Support\Facades\URL; use Illuminate\Validation\Rules\Password; class AuthServiceProvider extends ServiceProvider @@ -36,5 +38,16 @@ public function boot(): void 'email' => $notifiable->getEmailForPasswordReset(), ]); }; + + VerifyEmail::$createUrlCallback = function ($notifiable) { + return URL::temporarySignedRoute( + 'auth.verification.verify', + now()->addMinutes(config('auth.verification.expire', 60)), + [ + 'id' => $notifiable->getKey(), + 'hash' => sha1($notifiable->getEmailForVerification()), + ] + ); + }; } } diff --git a/lang/ro.json b/lang/ro.json index 5640e4c5..85496106 100644 --- a/lang/ro.json +++ b/lang/ro.json @@ -101,6 +101,9 @@ "auth.reset_password": "Resetează parola", + "auth.verify.unverified_notice": "Contul tău nu a fost încă verificat. Te rugăm să verifici emailul pentru a activa contul.", + "auth.verify.resend": "Trimite email de verificare", + "add_point.title": "Adaugă un punct pe hartă", "add_point.yes": "Da", "add_point.no": "Nu", diff --git a/resources/js/Components/Alert.vue b/resources/js/Components/Alert.vue index a4e6d5a2..90a1031b 100644 --- a/resources/js/Components/Alert.vue +++ b/resources/js/Components/Alert.vue @@ -1,9 +1,11 @@ diff --git a/resources/js/Components/EmailVerifiedAlert.vue b/resources/js/Components/EmailVerifiedAlert.vue new file mode 100644 index 00000000..ccfaae8b --- /dev/null +++ b/resources/js/Components/EmailVerifiedAlert.vue @@ -0,0 +1,38 @@ + + + diff --git a/resources/js/Layouts/DefaultLayout.vue b/resources/js/Layouts/DefaultLayout.vue index 33e54928..bcddbe1e 100644 --- a/resources/js/Layouts/DefaultLayout.vue +++ b/resources/js/Layouts/DefaultLayout.vue @@ -1,6 +1,8 @@ diff --git a/resources/js/Layouts/MapLayout.vue b/resources/js/Layouts/MapLayout.vue index 1db84f6d..2b5dcba7 100644 --- a/resources/js/Layouts/MapLayout.vue +++ b/resources/js/Layouts/MapLayout.vue @@ -118,8 +118,6 @@ diff --git a/resources/js/Pages/Home.vue b/resources/js/Pages/Home.vue index a6750fc7..320a80d7 100644 --- a/resources/js/Pages/Home.vue +++ b/resources/js/Pages/Home.vue @@ -2,7 +2,6 @@ -