diff --git a/app/Http/Controllers/EmailVerifyController.php b/app/Http/Controllers/EmailVerifyController.php index 5af0a49d..19c8554e 100644 --- a/app/Http/Controllers/EmailVerifyController.php +++ b/app/Http/Controllers/EmailVerifyController.php @@ -22,14 +22,16 @@ public function __invoke(EmailVerificationRequest $request): RedirectResponse public function create(): Response { - return Inertia::render("Auth/Verify-Email"); + return Inertia::render("Auth/VerifyEmail"); } public function send(Request $request): RedirectResponse { - $request->user()->sendEmailVerificationNotification(); + if (auth()->check()) { + $request->user()->sendEmailVerificationNotification(); + } return back() - ->with("message", "Wiadomość z linkiem aktywacyjnym została wysłana na Twój adres e-mail!"); + ->with("status", "Wiadomość z linkiem aktywacyjnym została wysłana na Twój adres e-mail!"); } } diff --git a/app/Http/Controllers/RegisterUserController.php b/app/Http/Controllers/RegisterUserController.php index 7c3dd6be..2458b9b5 100644 --- a/app/Http/Controllers/RegisterUserController.php +++ b/app/Http/Controllers/RegisterUserController.php @@ -26,6 +26,6 @@ public function store(RegisterUserRequest $request): RedirectResponse Auth::login($user); } - return Redirect::route("home"); + return Redirect::route("verification.notice"); } } diff --git a/resources/js/Pages/Auth/Verify-Email.vue b/resources/js/Pages/Auth/VerifyEmail.vue similarity index 100% rename from resources/js/Pages/Auth/Verify-Email.vue rename to resources/js/Pages/Auth/VerifyEmail.vue diff --git a/routes/web.php b/routes/web.php index d8c0f025..a9b06bce 100644 --- a/routes/web.php +++ b/routes/web.php @@ -22,9 +22,9 @@ use App\Models\Question; use Illuminate\Support\Facades\Route; -Route::get("/email/verify", [EmailVerifyController::class, "create"])->middleware("auth")->name("verification.notice"); +Route::get("/email/verify", [EmailVerifyController::class, "create"])->name("verification.notice"); Route::get("/email/{id}/{hash}", EmailVerifyController::class)->middleware(["auth", "throttle:6,1"])->name("verification.verify"); -Route::post("/email/verification-notification", [EmailVerifyController::class, "send"])->middleware("auth", "throttle:3,60")->name("verification.send"); +Route::post("/email/verification-notification", [EmailVerifyController::class, "send"])->middleware("throttle:3,60")->name("verification.send"); Route::post("/auth/logout", [AuthenticateSessionController::class, "logout"])->middleware("auth")->name("logout"); Route::middleware(["guest"])->group(function (): void { diff --git a/tests/Feature/RegisterUserTest.php b/tests/Feature/RegisterUserTest.php index 15fdf92c..96857346 100644 --- a/tests/Feature/RegisterUserTest.php +++ b/tests/Feature/RegisterUserTest.php @@ -25,7 +25,7 @@ public function testUserCanRegister(): void "password" => "123456890", "school_id" => $school->id, ]) - ->assertRedirect("/"); + ->assertRedirect("/email/verify"); $this->assertDatabaseHas("users", [ "name" => "Test", @@ -39,7 +39,7 @@ public function testUserCanRegister(): void ]); } - public function testUserCanNotCheckIfEmailIsAlreadyTakenViaRegisterForm(): void + public function testUserIsRedirectedToEmailVerifyIfEmailIsAlreadyTakenViaRegisterForm(): void { $school = School::factory()->create(); User::factory()->create([ @@ -53,7 +53,9 @@ public function testUserCanNotCheckIfEmailIsAlreadyTakenViaRegisterForm(): void "password" => "123456890", "school_id" => $school->id, ]) - ->assertRedirect("/"); + ->assertRedirect("/email/verify"); + + $this->assertGuest(); } public function testUserCanNotRegisterWithWrongSchoolIndex(): void