56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Auth;
|
|
|
|
use App\Enums\UserStatus;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('components.layouts.auth', [
|
|
'title' => 'Masuk Akun',
|
|
])]
|
|
class Login extends Component
|
|
{
|
|
#[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],
|
|
)) {
|
|
$this->redirectRoute('login', navigate: true);
|
|
|
|
return;
|
|
}
|
|
|
|
if (auth()->user()->status !== UserStatus::ACTIVE) {
|
|
auth()->logout();
|
|
|
|
$this->redirectRoute('login', navigate: true);
|
|
}
|
|
|
|
session()->regenerate();
|
|
|
|
$this->redirectIntended('/studio/dashboard/overview', navigate: true);
|
|
}
|
|
|
|
public function updated(string $prop, string $value)
|
|
{
|
|
$this->validateOnly($prop);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.auth.login');
|
|
}
|
|
}
|