college-courses/app/Http/Livewire/Login.php

49 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2024-10-15 10:15:40 +03:00
<?php
namespace App\Http\Livewire;
use App\Models\User;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
class Login extends Component implements HasForms
{
use InteractsWithForms;
public $name = '';
public $password = '';
protected function getFormSchema(): array
{
return [
TextInput::make('name')->label('Логин')->required()->placeholder('Введите логин...'),
TextInput::make('password')->label('Пароль')
->required()->password()
->dehydrated(fn ($state) => filled($state))
->placeholder('Введите пароль...'),
];
}
public function submit()
{
$state = $this->form->getState();
$user = User::query()->where('name', $state['name'])->first();
if (is_null($user)) {
return redirect();
}
if (Hash::check($state['password'], $user->password)) {
Auth::login($user, true);
return redirect('/');
}
}
public function render()
{
return view('livewire.login');
}
}