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,38 @@
<?php
namespace App\Classes\Frame;
use Illuminate\Support\Facades\Log;
use App\Classes\Server;
use App\User;
abstract class Action
{
const prefix = 'App\Classes\Frame\Action\\';
public $so = NULL;
public $uo = NULL;
public $action = NULL;
public $mode = NULL;
public $page = [];
public function __construct(Server $so,User $uo,int $action,int $mode)
{
$this->so = $so;
$this->uo = $uo;
$this->action = $action;
$this->mode = $mode;
}
public static function factory(string $class,Server $so,User $uo,int $action,int $mode)
{
$c = self::prefix.$class;
$o = class_exists($c) ? new $c($so,$uo,$action,$mode) : FALSE;
$so->log('debug',sprintf(($o ? 'Executing: %s' : 'Class doesnt exist: %s'),$c));
return $o;
}
abstract public function handle(array $fielddata);
}

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;
}
}

View File

@@ -16,7 +16,9 @@ class Ansi extends AbstractFrame
public static $cost_length = 7;
public static $cost_unit = 'u';
public function fields($startline=0,$fieldchar='.')
public static $if_filler = '.';
public function fields($startline=0)
{
$this->output .= str_replace(LF,CR.LF,$this->frame->content);
}

View File

@@ -17,7 +17,9 @@ class Videotex extends AbstractFrame
public static $cost_length = 7;
public static $cost_unit = 'u';
public function fields($startline=0,$fieldchar='.')
public static $if_filler = '.';
public function fields($startline=0)
{
$infield = FALSE; // In a field
$fieldtype = NULL; // Type of field
@@ -46,13 +48,13 @@ class Videotex extends AbstractFrame
$infield = TRUE;
$fieldlength = 1;
$fieldtype = ord(substr($this->frame->content,$posn+1,1))%128;
$this->output .= $fieldchar;
$this->output .= static::$if_filler;
} else {
if ($infield) {
if ($byte == $fieldtype) {
$fieldlength++;
$byte = ord($fieldchar); // Replace field with $fieldchar.
$byte = ord(static::$if_filler); // Replace field with static::$if_filler.
if ($fieldx === FALSE) {
$fieldx = $x;
@@ -79,7 +81,7 @@ class Videotex extends AbstractFrame
// Drop the last dot and replace it.
if ($fieldlength == 2) {
$datetime = date('D d M H:ia');
$this->output = rtrim($this->output,$fieldchar);
$this->output = rtrim($this->output,static::$if_filler);
$this->output .= $datetime{0};
}