2021-06-29 02:16:57 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class LoginForm extends Component
|
|
|
|
{
|
|
|
|
public $username = '';
|
|
|
|
public $password = '';
|
|
|
|
public $can_submit = false;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the validation rules for login
|
|
|
|
*
|
2021-06-29 10:28:00 -07:00
|
|
|
* @author A. Gianotto <snipe@snipe.net>
|
2021-06-29 02:16:57 -07:00
|
|
|
* @version v6.0
|
|
|
|
* @return Array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'username' => 'required|string|max:255',
|
|
|
|
'password' => 'required',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform the validation
|
|
|
|
*
|
2021-06-29 10:28:00 -07:00
|
|
|
* @author A. Gianotto <snipe@snipe.net>
|
2021-06-29 02:16:57 -07:00
|
|
|
* @version v6.0
|
|
|
|
*/
|
|
|
|
public function updated($fields)
|
|
|
|
{
|
2021-06-29 10:05:23 -07:00
|
|
|
|
|
|
|
if (is_null($fields) || empty($fields)) {
|
|
|
|
$this->can_submit = false;
|
|
|
|
}
|
|
|
|
|
2021-06-29 02:16:57 -07:00
|
|
|
$this->validateOnly($fields);
|
2021-06-29 10:05:23 -07:00
|
|
|
|
|
|
|
$this->can_submit = true;
|
2021-06-29 02:16:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actually do the login thing
|
|
|
|
*
|
2021-06-29 10:05:23 -07:00
|
|
|
* @todo fix missing LDAP stuff maybe? Not sure if it
|
|
|
|
* makes sense to even do this via LiveWire, since
|
|
|
|
* our login system is pretty complicated.
|
|
|
|
*
|
2021-06-29 10:28:00 -07:00
|
|
|
* @author A. Gianotto <snipe@snipe.net>
|
2021-06-29 02:16:57 -07:00
|
|
|
* @version v6.0
|
|
|
|
*/
|
|
|
|
public function submitForm()
|
|
|
|
{
|
|
|
|
|
2021-06-29 10:05:23 -07:00
|
|
|
$this->can_submit = true;
|
|
|
|
|
|
|
|
if (auth()->attempt($this->validate())) {
|
|
|
|
return redirect()->intended('/');
|
2021-06-29 02:16:57 -07:00
|
|
|
} else {
|
2021-06-29 10:05:23 -07:00
|
|
|
return session()->flash('error', trans('auth/message.account_not_found'));
|
2021-06-29 07:46:39 -07:00
|
|
|
}
|
2021-06-29 02:16:57 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|