BBS ported from vbbs
This commit is contained in:
158
app/Classes/BBS/Control/Register.php
Normal file
158
app/Classes/BBS/Control/Register.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\BBS\Control;
|
||||
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
use App\Classes\BBS\Control;
|
||||
use App\Mail\SendToken;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* 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->co,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=[]): string
|
||||
{
|
||||
// Ignore LF (as a result of pressing ENTER)
|
||||
if ($read == LF)
|
||||
return '';
|
||||
|
||||
// If we got a # we'll be completing field input.
|
||||
if ($read == HASH OR $read == CR) {
|
||||
// Does our field have data...
|
||||
if ($x=$this->so->fo->getFieldCurrentInput()) {
|
||||
switch ($this->so->fo->getFieldId()) {
|
||||
// Username
|
||||
case 0:
|
||||
// See if the requested username already exists
|
||||
if (User::where('login',$x)->exists()) {
|
||||
$this->so->sendBaseline($this->so->co,RED.'USER ALREADY EXISTS'.WHITE);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->so->sendBaseline($this->so->co,GREEN.'Enter Real Name'.WHITE);
|
||||
|
||||
break;
|
||||
|
||||
// Real Name
|
||||
case 1:
|
||||
//$this->data['name'] = $x;
|
||||
$this->so->sendBaseline($this->so->co,GREEN.'Enter Email Address'.WHITE);
|
||||
|
||||
break;
|
||||
|
||||
// Email Address
|
||||
case 2:
|
||||
if (Validator::make(['email'=>$x],[
|
||||
'email'=>'email',
|
||||
])->fails()) {
|
||||
$this->so->sendBaseline($this->so->co,RED.'INVALID EMAIL ADDRESS'.WHITE);
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
// See if the requested email already exists
|
||||
if (User::where('email',$x)->exists()) {
|
||||
$this->so->sendBaseline($this->so->co,RED.'USER ALREADY EXISTS'.WHITE);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->data['email'] = $x;
|
||||
$this->data['token'] = sprintf('%06.0f',rand(0,999999));
|
||||
|
||||
$this->so->sendBaseline($this->so->co,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->co,GREEN.'Enter Password'.WHITE);
|
||||
|
||||
break;
|
||||
|
||||
// Enter Password
|
||||
case 3:
|
||||
$this->data['password'] = $x;
|
||||
$this->so->sendBaseline($this->so->co,GREEN.'Confirm Password'.WHITE);
|
||||
|
||||
break;
|
||||
|
||||
// Confirm Password
|
||||
case 4:
|
||||
if ($this->data['password'] !== $x) {
|
||||
$this->so->sendBaseline($this->so->co,RED.'PASSWORD DOESNT MATCH, *09 TO START AGAIN'.WHITE);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->so->sendBaseline($this->so->co,GREEN.'Enter Location'.WHITE);
|
||||
|
||||
break;
|
||||
|
||||
// Enter Location
|
||||
case 5:
|
||||
$this->so->sendBaseline($this->so->co,GREEN.'Enter TOKEN emailed to you'.WHITE);
|
||||
|
||||
break;
|
||||
|
||||
// Enter Token
|
||||
case 6:
|
||||
if ($this->data['token'] !== $x) {
|
||||
$this->so->sendBaseline($this->so->co,RED.'TOKEN DOESNT MATCH, *09 TO START AGAIN'.WHITE);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->complete = TRUE;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->so->sendBaseline($this->so->co,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->co,RED.'FIELD REQUIRED...'.WHITE);
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $read;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user