public function Register($FormPostValues, $Options = array()) { $Valid = TRUE; $FormPostValues['LastIPAddress'] = Gdn::Request()->IpAddress(); // Check for banning first. $Valid = BanModel::CheckUser($FormPostValues, $this->Validation, TRUE); // Check for spam. if ($Valid) { $Spam = SpamModel::IsSpam('User', $FormPostValues); if ($Spam) { $Valid = FALSE; $this->Validation->AddValidationResult('Spam', 'You are not allowed to register at this time.'); } } // Throw an event to allow plugins to block the registration. $this->EventArguments['User'] = $FormPostValues; $this->EventArguments['Valid'] =& $Valid; $this->FireEvent('BeforeRegister'); if (!$Valid) return FALSE; // plugin blocked registration switch (strtolower(C('Garden.Registration.Method'))) { case 'captcha': $UserID = $this->InsertForBasic($FormPostValues, GetValue('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; case 'basic': default: $UserID = $this->InsertForBasic($FormPostValues, GetValue('CheckCaptcha', $Options, FALSE), $Options); break; } return $UserID; }
/** * Synchronizes the user based on a given UserKey. * * @param string $UserKey A string that uniquely identifies this user. * @param array $Data Information to put in the user table. * @return int The ID of the user. */ public function Synchronize($UserKey, $Data) { $UserID = 0; $Attributes = ArrayValue('Attributes', $Data); if (is_string($Attributes)) { $Attributes = @unserialize($Attributes); } if (!is_array($Attributes)) { $Attributes = array(); } // If the user didnt log in, they won't have a UserID yet. That means they want a new // account. So create one for them. if (!isset($Data['UserID']) || $Data['UserID'] <= 0) { // Prepare the user data. $UserData['Name'] = $Data['Name']; $UserData['Password'] = RandomString(16); $UserData['Email'] = ArrayValue('Email', $Data, '*****@*****.**'); $UserData['Gender'] = strtolower(substr(ArrayValue('Gender', $Data, 'u'), 0, 1)); $UserData['HourOffset'] = ArrayValue('HourOffset', $Data, 0); $UserData['DateOfBirth'] = ArrayValue('DateOfBirth', $Data, ''); $UserData['CountNotifications'] = 0; $UserData['Attributes'] = $Attributes; $UserData['InsertIPAddress'] = Gdn::Request()->IpAddress(); if ($UserData['DateOfBirth'] == '') { $UserData['DateOfBirth'] = '1975-09-16'; } // Make sure there isn't another user with this username. if ($this->ValidateUniqueFields($UserData['Name'], $UserData['Email'])) { if (!BanModel::CheckUser($UserData, $this->Validation, TRUE)) { throw PermissionException('Banned'); } // Insert the new user. $this->AddInsertFields($UserData); $UserID = $this->_Insert($UserData); } if ($UserID) { $NewUserRoleIDs = $this->NewUserRoleIDs(); // Save the roles. $Roles = GetValue('Roles', $Data, FALSE); if (empty($Roles)) { $Roles = $NewUserRoleIDs; } $this->SaveRoles($UserID, $Roles, FALSE); } } else { $UserID = $Data['UserID']; } // Synchronize the transientkey from the external user data source if it is present (eg. WordPress' wpnonce). if (array_key_exists('TransientKey', $Attributes) && $Attributes['TransientKey'] != '' && $UserID > 0) { $this->SetTransientKey($UserID, $Attributes['TransientKey']); } return $UserID; }
public function Register($FormPostValues, $Options = array()) { $Valid = TRUE; $FormPostValues['LastIPAddress'] = Gdn::Request()->IpAddress(); // Throw an error if the registering user has an active session if (Gdn::Session()->IsValid()) { $this->Validation->AddValidationResult('Name', 'You are already registered.'); } // Check for banning first. $Valid = BanModel::CheckUser($FormPostValues, $this->Validation, TRUE); // Throw an event to allow plugins to block the registration. unset($this->EventArguments['User']); $this->EventArguments['User'] = $FormPostValues; $this->EventArguments['Valid'] =& $Valid; $this->FireEvent('BeforeRegister'); if (!$Valid) { return FALSE; } // plugin blocked registration switch (strtolower(C('Garden.Registration.Method'))) { case 'captcha': $UserID = $this->InsertForBasic($FormPostValues, GetValue('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; case 'basic': default: $UserID = $this->InsertForBasic($FormPostValues, GetValue('CheckCaptcha', $Options, FALSE), $Options); break; } return $UserID; }