Login working

This commit is contained in:
Deon George
2018-12-11 23:31:44 +11:00
parent 4d65bb05a1
commit e60a7d9045
14 changed files with 289 additions and 92 deletions

View File

@@ -0,0 +1,56 @@
<?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->client(),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->client(),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->client(),RED.'INVALID PASSWORD, TRY AGAIN *00');
return FALSE;
}
$this->page = ['frame'=>1,'index'=>'a']; // @todo Get from DB.
$this->action = 2; // ACTION_GOTO
$this->mode = FALSE;
return TRUE;
}
}