191 lines
5.1 KiB
PHP
191 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Control;
|
|
|
|
use App\Classes\Control;
|
|
use App\Mail\SendToken;
|
|
use App\User;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
/**
|
|
* Class Register handles registration
|
|
*
|
|
* @todo REMOVE the force .WHITE at the end of each sendBaseline()
|
|
*
|
|
* @package App\Classes\Control
|
|
*/
|
|
class Register extends Control
|
|
{
|
|
private $data = [];
|
|
|
|
protected function boot()
|
|
{
|
|
$this->so->sendBaseline($this->so->client(),GREEN.'Select User Name'.WHITE);
|
|
}
|
|
|
|
/**
|
|
* Handle Registration Form Input
|
|
*
|
|
* This function assumes the form has 7 fields in a specific order.
|
|
*
|
|
* @todo Make this form more dynamic, or put some configuration in a config file, so that there is flexibility
|
|
* in field placement.
|
|
* @param string $read
|
|
* @param array $current
|
|
* @return string
|
|
*/
|
|
public function handle(string $read,array $current=[])
|
|
{
|
|
// Ignore CR
|
|
if ($read == CR)
|
|
return '';
|
|
|
|
// If we got a # we'll be completing field input.
|
|
if ($read == HASH OR $read == LF) {
|
|
|
|
// Our registration page
|
|
// @todo get this from the DB
|
|
if ($current['page']['frame'] == '981') {
|
|
|
|
// Does our field have data...
|
|
if (array_get($current['fielddata'],$current['fieldnum'])) {
|
|
switch ($current['fieldnum']) {
|
|
// Username
|
|
case 0:
|
|
// See if the requested username already exists
|
|
if (User::where('login', $current['fielddata'][$current['fieldnum']])->exists()) {
|
|
$this->so->sendBaseline($this->so->client(), RED . 'USER ALREADY EXISTS'.WHITE);
|
|
|
|
return '';
|
|
}
|
|
|
|
$this->data['user'] = $current['fielddata'][$current['fieldnum']];
|
|
$this->so->sendBaseline($this->so->client(), GREEN . 'Enter Real Name'.WHITE);
|
|
|
|
break;
|
|
|
|
// Real Name
|
|
case 1:
|
|
$this->data['name'] = $current['fielddata'][$current['fieldnum']];
|
|
$this->so->sendBaseline($this->so->client(), GREEN . 'Enter Email Address'.WHITE);
|
|
|
|
break;
|
|
|
|
// Email Address
|
|
case 2:
|
|
if (Validator::make(['email'=>$current['fielddata'][$current['fieldnum']]],[
|
|
'email'=>'email',
|
|
])->fails()) {
|
|
$this->so->sendBaseline($this->so->client(), RED . 'INVALID EMAIL ADDRESS'.WHITE);
|
|
|
|
return '';
|
|
};
|
|
|
|
// See if the requested email already exists
|
|
if (User::where('email', $current['fielddata'][$current['fieldnum']])->exists()) {
|
|
$this->so->sendBaseline($this->so->client(), RED . 'USER ALREADY EXISTS'.WHITE);
|
|
|
|
return '';
|
|
}
|
|
|
|
$this->data['email'] = $current['fielddata'][$current['fieldnum']];
|
|
$this->data['token'] = sprintf('%06.0f',rand(0,999999));
|
|
|
|
$this->so->sendBaseline($this->so->client(), YELLOW . 'PROCESSING...'.WHITE);
|
|
Mail::to($this->data['email'])->sendNow(new SendToken($this->data['token']));
|
|
|
|
if (Mail::failures()) {
|
|
dump('Failure?');
|
|
|
|
dump(Mail::failures());
|
|
}
|
|
|
|
$this->so->sendBaseline($this->so->client(), GREEN . 'Enter Password'.WHITE);
|
|
|
|
break;
|
|
|
|
// Enter Password
|
|
case 3:
|
|
$this->data['password'] = $current['fielddata'][$current['fieldnum']];
|
|
$this->so->sendBaseline($this->so->client(), GREEN . 'Confirm Password'.WHITE);
|
|
|
|
break;
|
|
|
|
// Confirm Password
|
|
case 4:
|
|
if ($this->data['password'] !== $current['fielddata'][$current['fieldnum']]) {
|
|
$this->so->sendBaseline($this->so->client(), RED . 'PASSWORD DOESNT MATCH, *09 TO START AGAIN'.WHITE);
|
|
|
|
return '';
|
|
}
|
|
|
|
$this->so->sendBaseline($this->so->client(), GREEN . 'Enter Location'.WHITE);
|
|
|
|
break;
|
|
|
|
// Enter Location
|
|
case 5:
|
|
$this->data['location'] = $current['fielddata'][$current['fieldnum']];
|
|
$this->so->sendBaseline($this->so->client(), GREEN . 'Enter TOKEN emailed to you'.WHITE);
|
|
|
|
break;
|
|
|
|
// Enter Token
|
|
case 6:
|
|
if ($this->data['token'] !== $current['fielddata'][$current['fieldnum']]) {
|
|
$this->so->sendBaseline($this->so->client(), RED . 'TOKEN DOESNT MATCH, *09 TO START AGAIN'.WHITE);
|
|
|
|
return '';
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
$this->so->sendBaseline($this->so->client(), RED . 'HUH?');
|
|
}
|
|
|
|
} else {
|
|
// If we are MODE_BL, we need to return the HASH, otherwise nothing.
|
|
if (in_array($this->state['mode'],[MODE_BL,MODE_SUBMITRF,MODE_RFNOTSENT])) {
|
|
return $read;
|
|
|
|
} else {
|
|
$this->so->sendBaseline($this->so->client(), RED . 'FIELD REQUIRED...'.WHITE);
|
|
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $read;
|
|
}
|
|
|
|
public function process()
|
|
{
|
|
$o = new User;
|
|
|
|
try {
|
|
$o->login = $this->data['user'];
|
|
$o->email = $this->data['email'];
|
|
$o->password = $this->data['password'];
|
|
$o->name = $this->data['name'];
|
|
$o->location = $this->data['location'];
|
|
|
|
$o->save();
|
|
$this->so->sendBaseline($this->so->client(), 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->client(), RED . 'SOMETHING WENT WRONG...'.WHITE);
|
|
$this->so->log('error',$e->getMessage());
|
|
$this->state['action'] = ACTION_RELOAD;
|
|
}
|
|
|
|
$this->complete = TRUE;
|
|
}
|
|
} |