Skip to content

Commit

Permalink
#60 - User do not get info about bad email in registration form (#77)
Browse files Browse the repository at this point in the history
* Add that if a guest user tries to register an existing email in the database, he is redirected to verify the email page with a false positive

* Fix tests

* Update resources/js/Pages/Auth/Verify-Email.vue

Co-authored-by: Ewelina Skrzypacz <56546832+EwelinaSkrzypacz@users.noreply.github.com>

* Change file name

* Fix key name while redirecting back in EmailVerifyController for future merge with frontend

* Simplify logic in EmailVerifyController

---------

Co-authored-by: Ewelina Skrzypacz <56546832+EwelinaSkrzypacz@users.noreply.github.com>
  • Loading branch information
PrabuckiDominik and EwelinaSkrzypacz authored Sep 6, 2024
1 parent 0924d62 commit a7bf744
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
8 changes: 5 additions & 3 deletions app/Http/Controllers/EmailVerifyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/RegisterUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public function store(RegisterUserRequest $request): RedirectResponse
Auth::login($user);
}

return Redirect::route("home");
return Redirect::route("verification.notice");
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions tests/Feature/RegisterUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testUserCanRegister(): void
"password" => "123456890",
"school_id" => $school->id,
])
->assertRedirect("/");
->assertRedirect("/email/verify");

$this->assertDatabaseHas("users", [
"name" => "Test",
Expand All @@ -39,7 +39,7 @@ public function testUserCanRegister(): void
]);
}

public function testUserCanNotCheckIfEmailIsAlreadyTakenViaRegisterForm(): void
public function testUserIsRedirectedToEmailVerifyIfEmailIsAlreadyTakenViaRegisterForm(): void
{
$school = School::factory()->create();
User::factory()->create([
Expand All @@ -53,7 +53,9 @@ public function testUserCanNotCheckIfEmailIsAlreadyTakenViaRegisterForm(): void
"password" => "123456890",
"school_id" => $school->id,
])
->assertRedirect("/");
->assertRedirect("/email/verify");

$this->assertGuest();
}

public function testUserCanNotRegisterWithWrongSchoolIndex(): void
Expand Down

0 comments on commit a7bf744

Please sign in to comment.