94 lines
4.2 KiB
PHP
94 lines
4.2 KiB
PHP
<?php
|
|
|
|
use Illuminate\Auth\Events\PasswordReset;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Password;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\Rules;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Volt\Component;
|
|
|
|
new #[Layout('layouts.guest')] class extends Component
|
|
{
|
|
#[Locked]
|
|
public string $token = '';
|
|
public string $email = '';
|
|
public string $password = '';
|
|
public string $password_confirmation = '';
|
|
|
|
public function mount(string $token): void
|
|
{
|
|
$this->token = $token;
|
|
$this->email = request()->string('email');
|
|
}
|
|
|
|
public function resetPassword(): void
|
|
{
|
|
$this->validate([
|
|
'token' => ['required'],
|
|
'email' => ['required', 'string', 'email'],
|
|
'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
|
|
]);
|
|
|
|
$status = Password::reset(
|
|
$this->only('email', 'password', 'password_confirmation', 'token'),
|
|
function ($user) {
|
|
$user->forceFill([
|
|
'password' => Hash::make($this->password),
|
|
'remember_token' => Str::random(60),
|
|
])->save();
|
|
|
|
event(new PasswordReset($user));
|
|
}
|
|
);
|
|
|
|
if ($status != Password::PASSWORD_RESET) {
|
|
$this->addError('email', __($status));
|
|
return;
|
|
}
|
|
|
|
Session::flash('status', __($status));
|
|
$this->redirectRoute('login', navigate: true);
|
|
}
|
|
}; ?>
|
|
|
|
<div>
|
|
<h2 style="font-size:1.25rem;font-weight:600;color:#f0f0f5;margin-bottom:1.5rem;">Set new password</h2>
|
|
|
|
<form wire:submit="resetPassword">
|
|
<div>
|
|
<label for="email" style="display:block;font-size:0.875rem;color:#8888a0;margin-bottom:0.375rem;">Email</label>
|
|
<input wire:model="email" id="email" type="email" name="email" required autofocus autocomplete="username"
|
|
style="width:100%;padding:0.5rem 0.75rem;background-color:#111117;border:1px solid rgba(255,255,255,0.06);border-radius:0.5rem;color:#f0f0f5;outline:none;"
|
|
onfocus="this.style.borderColor='#4f8ef7'" onblur="this.style.borderColor='rgba(255,255,255,0.06)'" />
|
|
<x-input-error :messages="$errors->get('email')" class="mt-2" />
|
|
</div>
|
|
|
|
<div style="margin-top:1rem;">
|
|
<label for="password" style="display:block;font-size:0.875rem;color:#8888a0;margin-bottom:0.375rem;">New Password</label>
|
|
<input wire:model="password" id="password" type="password" name="password" required autocomplete="new-password"
|
|
style="width:100%;padding:0.5rem 0.75rem;background-color:#111117;border:1px solid rgba(255,255,255,0.06);border-radius:0.5rem;color:#f0f0f5;outline:none;"
|
|
onfocus="this.style.borderColor='#4f8ef7'" onblur="this.style.borderColor='rgba(255,255,255,0.06)'" />
|
|
<x-input-error :messages="$errors->get('password')" class="mt-2" />
|
|
</div>
|
|
|
|
<div style="margin-top:1rem;">
|
|
<label for="password_confirmation" style="display:block;font-size:0.875rem;color:#8888a0;margin-bottom:0.375rem;">Confirm Password</label>
|
|
<input wire:model="password_confirmation" id="password_confirmation" type="password" name="password_confirmation" required autocomplete="new-password"
|
|
style="width:100%;padding:0.5rem 0.75rem;background-color:#111117;border:1px solid rgba(255,255,255,0.06);border-radius:0.5rem;color:#f0f0f5;outline:none;"
|
|
onfocus="this.style.borderColor='#4f8ef7'" onblur="this.style.borderColor='rgba(255,255,255,0.06)'" />
|
|
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
|
|
</div>
|
|
|
|
<div style="display:flex;justify-content:flex-end;margin-top:1.5rem;">
|
|
<button type="submit"
|
|
style="padding:0.5rem 1.5rem;background-color:#4f8ef7;color:#fff;border:none;border-radius:0.5rem;font-weight:500;cursor:pointer;"
|
|
onmouseover="this.style.opacity='.9'" onmouseout="this.style.opacity='1'">
|
|
Reset Password
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|