This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
vbbs/app/Classes/Frame/Action/Login.php

57 lines
1.3 KiB
PHP

<?php
namespace App\Classes\Frame\Action;
use App\User;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Log;
use App\Classes\Frame\Action;
class Login extends Action
{
/**
* Handle user logins
*
* @param array $fielddata
* @return bool
*/
public function handle(array $fielddata)
{
// First field data element is user, the second is the password
if (count($fielddata) != 2 OR ! array_get($fielddata,0) OR ! array_get($fielddata,1))
{
$this->mode = 2; // MODE_FIELD
// $this->action = 2; // ACTION_GOTO
$this->so->sendBaseline($this->so->co,RED.'INVALID DETAILS, TRY AGAIN *00');
return FALSE;
}
try {
$this->uo = User::where('login',array_get($fielddata,0))->firstOrFail();
} catch (ModelNotFoundException $e) {
$this->so->sendBaseline($this->so->co,RED.'USER NOT FOUND, TRY AGAIN *00');
return FALSE;
}
if ($this->uo->password != array_get($fielddata,1))
{
$this->uo = new User;
$this->so->sendBaseline($this->so->co,RED.'INVALID PASSWORD, TRY AGAIN *00');
return FALSE;
}
$this->so->log('info','User Login: '.$this->uo->name);
$this->page = ['frame'=>1,'index'=>'a']; // @todo Get from DB.
$this->action = 2; // ACTION_GOTO
$this->mode = FALSE;
return TRUE;
}
}