Enabled user registration
This commit is contained in:
190
app/Classes/Control/Register.php
Normal file
190
app/Classes/Control/Register.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?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;
|
||||
$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'];
|
||||
|
||||
try {
|
||||
$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;
|
||||
}
|
||||
}
|
101
app/Classes/Control/Telnet.php
Normal file
101
app/Classes/Control/Telnet.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Control;
|
||||
|
||||
use App\Classes\Control;
|
||||
|
||||
/**
|
||||
* Class Telnet
|
||||
*
|
||||
* This class looks after any telnet session commands
|
||||
*
|
||||
* TELNET http://pcmicro.com/netfoss/telnet.html
|
||||
*
|
||||
* @package App\Classes\Control
|
||||
*/
|
||||
class Telnet extends Control
|
||||
{
|
||||
private $option = FALSE;
|
||||
private $note = '';
|
||||
private $terminal = '';
|
||||
|
||||
public function handle(string $read)
|
||||
{
|
||||
$this->state['mode'] = FALSE;
|
||||
$this->so->log('debug',sprintf('Session Char (%s)',ord($read)),['complete'=>$this->complete,'option'=>$this->option]);
|
||||
|
||||
switch ($read) {
|
||||
// Command being sent.
|
||||
case TCP_IAC:
|
||||
$this->complete = FALSE;
|
||||
$this->note = 'IAC ';
|
||||
|
||||
break;
|
||||
|
||||
case TCP_SB:
|
||||
$this->option = TRUE;
|
||||
|
||||
break;
|
||||
|
||||
case TCP_SE:
|
||||
$this->option = FALSE;
|
||||
$this->complete = TRUE;
|
||||
$this->so->log('debug',sprintf('Session Terminal: %s',$this->terminal));
|
||||
|
||||
break;
|
||||
|
||||
case TCP_DO:
|
||||
$this->note .= 'DO ';
|
||||
|
||||
break;
|
||||
|
||||
case TCP_WILL:
|
||||
$this->note .= 'WILL ';
|
||||
|
||||
break;
|
||||
|
||||
case TCP_WONT:
|
||||
$this->note .= 'WONT ';
|
||||
|
||||
break;
|
||||
|
||||
case TCP_OPT_TERMTYPE:
|
||||
|
||||
break;
|
||||
|
||||
case TCP_OPT_ECHO:
|
||||
$this->note .= 'ECHO';
|
||||
$this->complete = TRUE;
|
||||
|
||||
$this->so->log('debug',sprintf('Session Note: %s',$this->note));
|
||||
|
||||
break;
|
||||
|
||||
case TCP_OPT_SUP_GOAHEAD:
|
||||
$this->note .= 'SUPPRESS GO AHEAD';
|
||||
$this->complete = TRUE;
|
||||
|
||||
$this->so->log('debug',sprintf('Session Note: %s',$this->note));
|
||||
|
||||
break;
|
||||
|
||||
case TCP_OPT_WINDOWSIZE:
|
||||
$this->note .= 'WINDOWSIZE';
|
||||
$this->complete = TRUE;
|
||||
|
||||
$this->so->log('debug',sprintf('Session Note: %s',$this->note));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($this->option AND $read) {
|
||||
$this->terminal .= $read;
|
||||
|
||||
} else {
|
||||
$this->so->log('debug',sprintf('Unhandled char in session_init: %s (%s)',$read,ord($read)));
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user