50 lines
1.0 KiB
PHP
50 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\BBS\Frame\Action;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use App\Classes\BBS\Exceptions\{ActionMissingInputsException,InvalidPasswordException};
|
|
use App\Classes\BBS\Frame\{Action,Field};
|
|
use App\Classes\BBS\Server;
|
|
use App\Models\User;
|
|
|
|
class Login extends Action
|
|
{
|
|
protected const fields = ['USER','PASS'];
|
|
|
|
public function __get(string $key): mixed
|
|
{
|
|
switch ($key) {
|
|
case 'user': return $this->uo;
|
|
|
|
default:
|
|
return parent::__get($key);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle user logins
|
|
*
|
|
* @return bool
|
|
* @throws ActionMissingInputsException
|
|
* @throws InvalidPasswordException
|
|
*/
|
|
public function handle(): bool
|
|
{
|
|
parent::init();
|
|
|
|
$this->uo = User::where('name',$this->USER)->orWhere('alias',$this->USER)->firstOrFail();
|
|
|
|
if (! Hash::check($this->PASS,$this->uo->password))
|
|
throw new InvalidPasswordException(sprintf('Password doesnt match for [%s]',$this->USER));
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
public function preSubmitField(Server $server,Field $field): ?string
|
|
{
|
|
// Noop
|
|
return NULL;
|
|
}
|
|
} |