coolify/app/Livewire/ForcePasswordReset.php

55 lines
1.3 KiB
PHP
Raw Normal View History

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