-
Notifications
You must be signed in to change notification settings - Fork 504
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
Beautify Livewire Stack #326
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c7138be
refactoring initial
taylorotwell 2eaba3f
fix missing variable
taylorotwell 0358cfa
refactor
taylorotwell 10c79bb
extract login form
taylorotwell a7896a2
extract logout
taylorotwell e82ea3d
fix errors
taylorotwell 85cd9a4
refactor functional stack
taylorotwell 8bff5e8
spacing
taylorotwell 713700e
import function
taylorotwell 5c4c6f9
update pest tests
taylorotwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,13 +1,16 @@ | ||||||||||
<?php | ||||||||||
|
||||||||||
use App\Livewire\Actions\Logout; | ||||||||||
use App\Providers\RouteServiceProvider; | ||||||||||
use Illuminate\Support\Facades\Auth; | ||||||||||
use Illuminate\Support\Facades\Session; | ||||||||||
|
||||||||||
use function Livewire\Volt\layout; | ||||||||||
|
||||||||||
layout('layouts.guest'); | ||||||||||
|
||||||||||
$sendVerification = function () { | ||||||||||
if (auth()->user()->hasVerifiedEmail()) { | ||||||||||
if (Auth::user()->hasVerifiedEmail()) { | ||||||||||
$this->redirect( | ||||||||||
session('url.intended', RouteServiceProvider::HOME), | ||||||||||
navigate: true | ||||||||||
|
@@ -16,16 +19,13 @@ | |||||||||
return; | ||||||||||
} | ||||||||||
|
||||||||||
auth()->user()->sendEmailVerificationNotification(); | ||||||||||
Auth::user()->sendEmailVerificationNotification(); | ||||||||||
|
||||||||||
session()->flash('status', 'verification-link-sent'); | ||||||||||
Session::flash('status', 'verification-link-sent'); | ||||||||||
}; | ||||||||||
|
||||||||||
$logout = function () { | ||||||||||
auth()->guard('web')->logout(); | ||||||||||
|
||||||||||
session()->invalidate(); | ||||||||||
session()->regenerateToken(); | ||||||||||
$logout = function (Logout $logout) { | ||||||||||
$logout(); | ||||||||||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
$this->redirect('/', navigate: true); | ||||||||||
}; | ||||||||||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion it is a bad idea to have the same name for the callback and action, because I thought the Closure is calling itself.