-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactoring initial * fix missing variable * refactor * extract login form * extract logout * fix errors * refactor functional stack * spacing * import function * update pest tests
- Loading branch information
1 parent
72541b1
commit c348b02
Showing
25 changed files
with
241 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Actions; | ||
|
||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Session; | ||
|
||
class Logout | ||
{ | ||
/** | ||
* Log the current user out of the application. | ||
*/ | ||
public function __invoke(): void | ||
{ | ||
Auth::guard('web')->logout(); | ||
|
||
Session::invalidate(); | ||
Session::regenerateToken(); | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Forms; | ||
|
||
use Illuminate\Auth\Events\Lockout; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\RateLimiter; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Validation\ValidationException; | ||
use Livewire\Attributes\Rule; | ||
use Livewire\Form; | ||
|
||
class LoginForm extends Form | ||
{ | ||
#[Rule('required|string|email')] | ||
public string $email = ''; | ||
|
||
#[Rule('required|string')] | ||
public string $password = ''; | ||
|
||
#[Rule('boolean')] | ||
public bool $remember = false; | ||
|
||
/** | ||
* Attempt to authenticate the request's credentials. | ||
* | ||
* @throws \Illuminate\Validation\ValidationException | ||
*/ | ||
public function authenticate(): void | ||
{ | ||
$this->ensureIsNotRateLimited(); | ||
|
||
if (! Auth::attempt($this->only(['email', 'password']), $this->remember)) { | ||
RateLimiter::hit($this->throttleKey()); | ||
|
||
throw ValidationException::withMessages([ | ||
'email' => trans('auth.failed'), | ||
]); | ||
} | ||
|
||
RateLimiter::clear($this->throttleKey()); | ||
} | ||
|
||
/** | ||
* Ensure the authentication request is not rate limited. | ||
*/ | ||
protected function ensureIsNotRateLimited(): void | ||
{ | ||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { | ||
return; | ||
} | ||
|
||
event(new Lockout(request())); | ||
|
||
$seconds = RateLimiter::availableIn($this->throttleKey()); | ||
|
||
throw ValidationException::withMessages([ | ||
'email' => trans('auth.throttle', [ | ||
'seconds' => $seconds, | ||
'minutes' => ceil($seconds / 60), | ||
]), | ||
]); | ||
} | ||
|
||
/** | ||
* Get the authentication rate limiting throttle key. | ||
*/ | ||
protected function throttleKey(): string | ||
{ | ||
return Str::transliterate(Str::lower($this->email).'|'.request()->ip()); | ||
} | ||
} |
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
7 changes: 3 additions & 4 deletions
7
stubs/livewire-functional/resources/views/livewire/layout/navigation.blade.php
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
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
10 changes: 5 additions & 5 deletions
10
stubs/livewire-functional/resources/views/livewire/profile/delete-user-form.blade.php
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
Oops, something went wrong.