1
0
Fork 0

Adding LoginForm Livewire component

This commit is contained in:
Henrik Hautakoski 2021-12-31 17:12:40 +01:00
parent d40008aafc
commit 62b32d36e7
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,43 @@
<?php
namespace App\Http\Livewire\Form;
use Livewire\Component;
use Illuminate\Support\Facades\Auth;
class LoginForm extends Component
{
public $username;
public $password;
protected $rules = [
'username' => 'required|string|min:3',
'password' => 'required|string',
];
public function submit()
{
$this->validate();
$cred = [
'username' => $this->username,
'password' => $this->password
];
if (!Auth::attempt($cred)) {
session()->flash('message', __('auth.failed'));
return;
}
return redirect()->intended('/admin');
}
/**
* Render the setup page
*/
public function render()
{
return view('form.login');
}
}

View file

@ -0,0 +1,17 @@
<form class="space-y-4" wire:submit.prevent="submit">
@if (Session::has('message'))
<p class="text-center text-red-400">{{ Session::get('message') }}</p>
@endif
<div>
<x-ignite-label class="sr-only" for="username">Username</x-ignite-label>
<x-ignite-input name="username" wire:model="username" placeholder="Username" class="" />
</div>
<div>
<label class="sr-only" for="password">Password</label>
<x-ignite-input name="password" wire:model="password" type="password" placeholder="Password" />
</div>
<x-button element="input" wire:click="submit" class="w-full" type="info" value="Login" />
</form>