2023-08-15 12:11:38 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire;
|
2023-08-15 12:11:38 +00:00
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2023-08-15 12:27:45 +00:00
|
|
|
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
|
2023-08-15 12:11:38 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class ForcePasswordReset extends Component
|
|
|
|
{
|
2023-08-15 12:27:45 +00:00
|
|
|
use WithRateLimiting;
|
2023-08-15 12:11:38 +00:00
|
|
|
public string $email;
|
|
|
|
public string $password;
|
|
|
|
public string $password_confirmation;
|
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'email' => 'required|email',
|
|
|
|
'password' => 'required|min:8',
|
|
|
|
'password_confirmation' => 'required|same:password',
|
|
|
|
];
|
2023-09-06 10:07:34 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-15 12:11:38 +00:00
|
|
|
$this->email = auth()->user()->email;
|
|
|
|
}
|
2024-01-07 15:23:41 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.force-password-reset')->layout('layouts.simple');
|
|
|
|
}
|
2023-09-06 10:07:34 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
2023-08-15 12:11:38 +00:00
|
|
|
try {
|
2023-08-15 12:27:45 +00:00
|
|
|
$this->rateLimit(10);
|
2023-08-15 12:11:38 +00:00
|
|
|
$this->validate();
|
2023-09-06 10:07:34 +00:00
|
|
|
$firstLogin = auth()->user()->created_at == auth()->user()->updated_at;
|
2023-08-15 12:11:38 +00:00
|
|
|
auth()->user()->forceFill([
|
|
|
|
'password' => Hash::make($this->password),
|
|
|
|
'force_password_reset' => false,
|
|
|
|
])->save();
|
2023-09-06 10:07:34 +00:00
|
|
|
if ($firstLogin) {
|
|
|
|
send_internal_notification('First login for ' . auth()->user()->email);
|
|
|
|
}
|
2023-12-27 15:45:01 +00:00
|
|
|
return redirect()->route('dashboard');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-08-15 12:11:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|