69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Auth;
|
|
|
|
use App\Enums\UserStatus;
|
|
use App\Traits\WithUpdatedData;
|
|
use Flux\Flux;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('components.layouts.auth', [
|
|
'title' => 'Masuk Akun',
|
|
])]
|
|
class Login extends Component
|
|
{
|
|
use WithUpdatedData;
|
|
|
|
#[Validate(['required', 'string'], attribute: 'nama pengguna atau alamat surel')]
|
|
public string $login = '';
|
|
|
|
#[Validate('required', attribute: 'kata sandi')]
|
|
public string $password = '';
|
|
|
|
public function auth()
|
|
{
|
|
$this->validate();
|
|
|
|
$identifier = filter_var($this->login, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
|
|
|
|
if (! auth()->attempt(
|
|
[$identifier => $this->login, 'password' => $this->password],
|
|
)) {
|
|
|
|
Flux::toast(
|
|
heading: 'Gagal',
|
|
text: 'Nama pengguna, email atau kata sandi salah.',
|
|
variant: 'danger',
|
|
duration: 3000
|
|
);
|
|
|
|
$this->redirectRoute('login', navigate: true);
|
|
|
|
return;
|
|
}
|
|
|
|
if (auth()->user()->status !== UserStatus::ACTIVE) {
|
|
auth()->logout();
|
|
|
|
$this->redirectRoute('login', navigate: true);
|
|
}
|
|
|
|
Flux::toast(
|
|
heading: 'Berhasil',
|
|
text: 'Selamat datang, '.auth()->user()?->employee?->full_name.'. Semoga harimu menyenangkan.',
|
|
variant: 'success',
|
|
duration: 3000
|
|
);
|
|
|
|
session()->regenerate();
|
|
$this->redirectIntended('/studio/dashboard/overview', navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.auth.login');
|
|
}
|
|
}
|