clusev/app/Livewire/Auth/PasswordChange.php

44 lines
1.2 KiB
PHP

<?php
namespace App\Livewire\Auth;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('layouts.auth')]
class PasswordChange extends Component
{
public string $current = '';
public string $password = '';
public string $password_confirmation = '';
public function update()
{
$this->validate([
'current' => ['required', 'current_password'],
'password' => ['required', 'confirmed', Password::min(12)->mixedCase()->numbers()],
], attributes: [
'current' => __('auth.attr_current_password'),
'password' => __('auth.attr_new_password'),
]);
Auth::user()->forceFill([
'password' => Hash::make($this->password),
'must_change_password' => false,
])->save();
// onboarding continues: the middleware sends an un-enrolled user to 2FA setup.
return $this->redirect(route('two-factor.setup'), navigate: true);
}
public function render()
{
return view('livewire.auth.password-change')->title(__('auth.title_password_change'));
}
}