Inicio de sesion y probando con octane + frankenphp
This commit is contained in:
44
app/Livewire/Auth/ForgotPassword.php
Normal file
44
app/Livewire/Auth/ForgotPassword.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Auth;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use TallStackUi\Traits\Interactions;
|
||||
|
||||
#[Layout('components.layouts.login')]
|
||||
class ForgotPassword extends Component
|
||||
{
|
||||
use Interactions;
|
||||
|
||||
#[Validate('required|email')]
|
||||
public $email = '';
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.auth.forgot-password');
|
||||
}
|
||||
|
||||
public function recover(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$status = Password::sendResetLink(['email' => $this->email]);
|
||||
|
||||
if ($status === Password::RESET_LINK_SENT) {
|
||||
$this->dialog()->success('Correo enviado', __($status))
|
||||
->confirm(method: 'redirectToLogin')
|
||||
->send();
|
||||
} else {
|
||||
$this->dialog()->error('Error', __($status))->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function redirectToLogin(): void
|
||||
{
|
||||
$this->redirect(route('login'));
|
||||
}
|
||||
}
|
||||
80
app/Livewire/Auth/Login.php
Normal file
80
app/Livewire/Auth/Login.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
#[Layout('components.layouts.login')]
|
||||
class Login extends Component
|
||||
{
|
||||
#[Validate('required|string|email')]
|
||||
public $email = '';
|
||||
|
||||
#[Validate('required|string')]
|
||||
public string $password = '';
|
||||
|
||||
#[Validate('boolean')]
|
||||
public bool $remember = false;
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.auth.login');
|
||||
}
|
||||
|
||||
public function login(): void
|
||||
{
|
||||
Session::invalidate();
|
||||
|
||||
$this->authenticate();
|
||||
Session::regenerate();
|
||||
|
||||
$this->redirectIntended(route('home.index'));
|
||||
}
|
||||
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->validate();
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('email', 'password'), $this->remember)) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
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),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->email).'|'.request()->ip());
|
||||
}
|
||||
}
|
||||
67
app/Livewire/Auth/ResetPassword.php
Normal file
67
app/Livewire/Auth/ResetPassword.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use TallStackUi\Traits\Interactions;
|
||||
|
||||
#[Layout('components.layouts.login')]
|
||||
class ResetPassword extends Component
|
||||
{
|
||||
use Interactions;
|
||||
|
||||
#[Url]
|
||||
#[Validate('required|email')]
|
||||
public $email;
|
||||
|
||||
#[Validate('required')]
|
||||
public $token;
|
||||
|
||||
#[Validate('required|min:8|confirmed')]
|
||||
public $password;
|
||||
|
||||
#[Validate('required')]
|
||||
public $password_confirmation;
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.auth.reset-password');
|
||||
}
|
||||
|
||||
public function resetPassword(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$status = Password::reset(
|
||||
[
|
||||
'email' => $this->email,
|
||||
'token' => $this->token,
|
||||
'password' => $this->password,
|
||||
'password_confirmation' => $this->password_confirmation,
|
||||
],
|
||||
function (User $user, string $password) {
|
||||
$user->forceFill(['password' => Hash::make($password)])->setRememberToken(Str::random(60));
|
||||
$user->save();
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
if ($status === Password::PASSWORD_RESET) {
|
||||
Session::flash('toast', ['type' => 'success', 'message' => __($status)]);
|
||||
$this->redirectRoute('login', navigate: true);
|
||||
} else {
|
||||
throw ValidationException::withMessages(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user