update email address change info to use session based banners

This commit is contained in:
Gregor Vostrak
2026-05-26 14:03:30 +02:00
committed by Constantin Graf
parent cb8047028c
commit 372c7b02a0
2 changed files with 43 additions and 12 deletions

View File

@@ -36,10 +36,9 @@ class UserController extends Controller
->exists(); ->exists();
if ($emailAlreadyInUse) { if ($emailAlreadyInUse) {
return redirect(route('dashboard', [ return redirect(route('dashboard'))
'bannerStyle' => 'danger', ->with('bannerStyle', 'danger')
'bannerText' => __('The email address is already in use.'), ->with('bannerText', __('The email address is already in use.'));
]));
} }
$user->email = $email; $user->email = $email;
@@ -47,9 +46,8 @@ class UserController extends Controller
$user->email_verified_at = Carbon::now(); $user->email_verified_at = Carbon::now();
$user->save(); $user->save();
return redirect(route('dashboard', [ return redirect(route('dashboard'))
'bannerStyle' => 'success', ->with('bannerStyle', 'success')
'bannerText' => __('Your email address has been updated successfully.'), ->with('bannerText', __('Your email address has been updated successfully.'));
]));
} }
} }

View File

@@ -108,10 +108,9 @@ class ProfileInformationTest extends TestCase
$response = $this->get($verificationUrl); $response = $this->get($verificationUrl);
// Assert // Assert
$response->assertRedirect(route('dashboard', [ $response->assertRedirect(route('dashboard'));
'bannerStyle' => 'success', $response->assertSessionHas('bannerStyle', 'success');
'bannerText' => 'Your email address has been updated successfully.', $response->assertSessionHas('bannerText', 'Your email address has been updated successfully.');
]));
$user = $user->fresh(); $user = $user->fresh();
$this->assertEquals('new.email@example.com', $user->email); $this->assertEquals('new.email@example.com', $user->email);
$this->assertNull($user->pending_email); $this->assertNull($user->pending_email);
@@ -144,6 +143,40 @@ class ProfileInformationTest extends TestCase
$this->assertEquals('new.email@example.com', $user->pending_email); $this->assertEquals('new.email@example.com', $user->pending_email);
} }
public function test_pending_email_verification_redirects_with_danger_banner_when_email_already_in_use(): void
{
// Arrange
User::factory()->create([
'email' => 'taken@example.com',
'is_placeholder' => false,
]);
$user = User::factory()->create([
'email' => 'current@example.com',
'pending_email' => 'taken@example.com',
]);
$this->actingAs($user);
$verificationUrl = URL::temporarySignedRoute(
'users.verify-email-change',
now()->addMinutes(60),
[
'user' => $user->getKey(),
'email' => 'taken@example.com',
],
false
);
// Act
$response = $this->get($verificationUrl);
// Assert
$response->assertRedirect(route('dashboard'));
$response->assertSessionHas('bannerStyle', 'danger');
$response->assertSessionHas('bannerText', 'The email address is already in use.');
$user = $user->fresh();
$this->assertEquals('current@example.com', $user->email);
$this->assertEquals('taken@example.com', $user->pending_email);
}
public function test_stale_pending_email_verification_link_is_rejected(): void public function test_stale_pending_email_verification_link_is_rejected(): void
{ {
// Arrange // Arrange