Moved registration processing into Frame/Action

This commit is contained in:
Deon George
2019-07-14 22:43:31 +10:00
parent 264747e2f3
commit aa6b2f3244
9 changed files with 316 additions and 217 deletions

View File

@@ -34,5 +34,5 @@ abstract class Action
return $o;
}
abstract public function handle(array $fielddata);
abstract public function handle();
}

View File

@@ -16,10 +16,10 @@ class Login extends Action
* @param array $fielddata
* @return bool
*/
public function handle(array $fielddata)
public function handle()
{
// 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))
if (count($this->so->fo->getFieldData()) != 2 OR ! $this->so->fo->getFieldDataId(0) OR ! $this->so->fo->getFieldDataId(1))
{
$this->mode = 2; // MODE_FIELD
// $this->action = 2; // ACTION_GOTO
@@ -30,7 +30,7 @@ class Login extends Action
}
try {
$this->uo = User::where('login',array_get($fielddata,0))->firstOrFail();
$this->uo = User::where('login',$this->so->fo->getFieldDataId(0))->firstOrFail();
} catch (ModelNotFoundException $e) {
$this->so->sendBaseline($this->so->co,RED.'USER NOT FOUND, TRY AGAIN *00');
@@ -38,7 +38,7 @@ class Login extends Action
return FALSE;
}
if ($this->uo->password != array_get($fielddata,1))
if ($this->uo->password != $this->so->fo->getFieldDataId(1))
{
$this->uo = new User;
$this->so->sendBaseline($this->so->co,RED.'INVALID PASSWORD, TRY AGAIN *00');

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Classes\Frame\Action;
use App\User;
use App\Classes\Frame\Action;
/**
* Class Register
* This handles the data received for account registration
*
* @package App\Classes\Frame\Action
*/
class Register extends Action
{
/**
* Handle user logins
*
* @param array $fielddata
* @return bool
*/
public function handle()
{
$o = new User;
try {
$o->login = $this->so->fo->getFieldDataId(0);
$o->name = $this->so->fo->getFieldDataId(1);
$o->email = $this->so->fo->getFieldDataId(2);
$o->password = $this->so->fo->getFieldDataId(3);
$o->location = $this->so->fo->getFieldDataId(5);
$o->save();
$this->so->sendBaseline($this->so->co,GREEN.'ACCOUNT CREATED, PRESS '.HASH.' TO CONTINUE...'.WHITE);
$this->state['action'] = ACTION_NEXT;
// Add to CUG 0
$o->cugs()->attach(0);
} catch (\Exception $e) {
$this->so->sendBaseline($this->so->co,RED.'SOMETHING WENT WRONG...'.WHITE);
$this->so->log('error',$e->getMessage());
$this->state['action'] = ACTION_RELOAD;
}
}
}