public function register($FormPostValues, $Options = [])
{
$FormPostValues['LastIPAddress'] = ipEncode(Gdn::request()->ipAddress());
// Check for banning first.
$Valid = BanModel::checkUser($FormPostValues, null, true);
if (!$Valid) {
$this->Validation->addValidationResult('UserID', 'Sorry, permission denied.');
}
// Throw an event to allow plugins to block the registration.
unset($this->EventArguments['User']);
$this->EventArguments['RegisteringUser'] =& $FormPostValues;
$this->EventArguments['Valid'] =& $Valid;
$this->fireEvent('BeforeRegister');
if (!$Valid) {
return false;
// plugin blocked registration
}
if (array_key_exists('Gender', $FormPostValues)) {
$FormPostValues['Gender'] = self::fixGender($FormPostValues['Gender']);
}
$Method = strtolower(val('Method', $Options, c('Garden.Registration.Method')));
switch ($Method) {
case 'basic':
case 'captcha':
// deprecated
$UserID = $this->insertForBasic($FormPostValues, val('CheckCaptcha', $Options, true), $Options);
break;
case 'approval':
$UserID = $this->insertForApproval($FormPostValues, $Options);
break;
case 'invitation':
$UserID = $this->insertForInvite($FormPostValues, $Options);
break;
case 'closed':
$UserID = false;
$this->Validation->addValidationResult('Registration', 'Registration is closed.');
break;
default:
$UserID = $this->insertForBasic($FormPostValues, val('CheckCaptcha', $Options, false), $Options);
break;
}
if ($UserID) {
$this->EventArguments['UserID'] = $UserID;
$this->fireEvent('AfterRegister');
}
return $UserID;
}