Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#60 - User do not get info about bad email in registration form #77

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");
}
}
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
Loading