BBS ported from vbbs
This commit is contained in:
50
app/Classes/BBS/Frame/Action/Login.php
Normal file
50
app/Classes/BBS/Frame/Action/Login.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user