public function insertForBasic($FormPostValues, $CheckCaptcha = true, $Options = [])
{
$RoleIDs = RoleModel::getDefaultRoles(RoleModel::TYPE_MEMBER);
if (!is_array($RoleIDs) || count($RoleIDs) == 0) {
throw new Exception(t('The default role has not been configured.'), 400);
}
if (val('SaveRoles', $Options)) {
$RoleIDs = val('RoleID', $FormPostValues);
}
$UserID = false;
// Define the primary key in this model's table.
$this->defineSchema();
// Add & apply any extra validation rules.
if (val('ValidateEmail', $Options, true)) {
$this->Validation->applyRule('Email', 'Email');
}
// TODO: DO I NEED THIS?!
// Make sure that the checkbox val for email is saved as the appropriate enum
if (array_key_exists('ShowEmail', $FormPostValues)) {
$FormPostValues['ShowEmail'] = forceBool($FormPostValues['ShowEmail'], '0', '1', '0');
}
if (array_key_exists('Banned', $FormPostValues)) {
$FormPostValues['Banned'] = forceBool($FormPostValues['Banned'], '0', '1', '0');
}
$this->addInsertFields($FormPostValues);
if ($this->validate($FormPostValues, true) === true) {
$Fields = $this->Validation->validationFields();
// All fields on the form that need to be validated (including non-schema field rules defined above)
$Username = val('Name', $Fields);
$Email = val('Email', $Fields);
$Fields = $this->Validation->schemaValidationFields();
// Only fields that are present in the schema
$Fields['Roles'] = $RoleIDs;
unset($Fields[$this->PrimaryKey]);
// If in Captcha registration mode, check the captcha value.
if ($CheckCaptcha && Captcha::enabled()) {
$captchaIsValid = Captcha::validate();
if ($captchaIsValid !== true) {
$this->Validation->addValidationResult('Garden.Registration.CaptchaPublicKey', 'The captcha was not completed correctly. Please try again.');
return false;
}
}
if (!$this->validateUniqueFields($Username, $Email)) {
return false;
}
// Check for spam.
if (val('ValidateSpam', $Options, true)) {
$ValidateSpam = $this->validateSpamRegistration($FormPostValues);
if ($ValidateSpam !== true) {
return $ValidateSpam;
}
}
// Define the other required fields:
$Fields['Email'] = $Email;
// And insert the new user
$UserID = $this->insertInternal($Fields, $Options);
if ($UserID > 0 && !val('NoActivity', $Options)) {
$ActivityModel = new ActivityModel();
$ActivityModel->save(['ActivityUserID' => $UserID, 'ActivityType' => 'Registration', 'HeadlineFormat' => t('HeadlineFormat.Registration', '{ActivityUserID,You} joined.'), 'Story' => t('Welcome Aboard!')], false, ['GroupBy' => 'ActivityTypeID']);
}
}
return $UserID;
}