This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: throttle verification mail resending in UI (#116)
- Loading branch information
Showing
8 changed files
with
128 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div class="flex max-w-xl p-8 mx-auto my-6 bg-white rounded-lg"> | ||
<div class="flex flex-col w-full text-center space-y-6"> | ||
<div class="space-y-4"> | ||
<h1>@lang('fortify::auth.verify.page_header')</h1> | ||
|
||
<p>@lang('fortify::auth.verify.link_description')</p> | ||
</div> | ||
|
||
<img class="mb-5 mx-12" src="/images/auth/verify-email.svg" /> | ||
|
||
<form wire:click.prevent="resend" wire:poll> | ||
<p class="text-sm text-theme-secondary-600 lg:no-wrap-span-children"> | ||
<span>@lang('fortify::auth.verify.line_1')</span> | ||
<span>@lang('fortify::auth.verify.line_2')</span> | ||
|
||
@if($this->rateLimitReached()) | ||
<span class="link" data-tippy-content="@lang('fortify::messages.resend_email_verification_limit')"> | ||
@lang('fortify::actions.resend_email_verification') | ||
</span> | ||
@else | ||
<button wire:loading.attr="disabled" type="submit" class="link"> | ||
@lang('fortify::actions.resend_email_verification') | ||
</button> | ||
@endif | ||
</p> | ||
</form> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ARKEcosystem\Fortify\Components; | ||
|
||
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException; | ||
use DanHarrin\LivewireRateLimiting\WithRateLimiting; | ||
use Illuminate\Support\Facades\RateLimiter; | ||
use Illuminate\View\View; | ||
use Laravel\Fortify\Http\Controllers\EmailVerificationNotificationController; | ||
use Livewire\Component; | ||
|
||
class VerifyEmail extends Component | ||
{ | ||
use WithRateLimiting; | ||
|
||
private const MAX_ATTEMPTS = 1; | ||
|
||
private const DECAY_SECONDS = 5 * 60; | ||
|
||
public function render(): View | ||
{ | ||
return view('ark-fortify::components.auth-verify-email'); | ||
} | ||
|
||
public function resend(): void | ||
{ | ||
try { | ||
$this->rateLimit(self::MAX_ATTEMPTS, self::DECAY_SECONDS); | ||
} catch (TooManyRequestsException $e) { | ||
return; | ||
} | ||
|
||
(new EmailVerificationNotificationController())->store(request()); | ||
} | ||
|
||
public function rateLimitReached(): bool | ||
{ | ||
return RateLimiter::tooManyAttempts($this->getRateLimitKey('resend'), self::MAX_ATTEMPTS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use ARKEcosystem\Fortify\Components\VerifyEmail; | ||
use Livewire\Livewire; | ||
|
||
use function Tests\createUserModel; | ||
|
||
it('can resend a verification email', function (): void { | ||
Livewire::actingAs(createUserModel()) | ||
->test(VerifyEmail::class) | ||
->call('resend') | ||
->assertDontSee(trans('fortify::messages.resend_email_verification_limit')); | ||
}); | ||
|
||
it('can resend a verification email once every 5 minutes', function (): void { | ||
$component = Livewire::actingAs(createUserModel()) | ||
->test(VerifyEmail::class) | ||
->call('resend') | ||
->call('resend') | ||
->assertSee(trans('fortify::messages.resend_email_verification_limit')); | ||
|
||
$this->travel(6)->minutes(); | ||
|
||
$component->call('$refresh')->assertDontSee(trans('fortify::messages.resend_email_verification_limit')); | ||
}); |