/** * Configuration of registration settings. * * Events: BeforeRegistrationUpdate * * @since 2.0.0 * @access public * @param string $RedirectUrl Where to send user after registration. */ public function registration($RedirectUrl = '') { $this->permission('Garden.Settings.Manage'); $this->addSideMenu('dashboard/settings/registration'); $this->addJsFile('registration.js'); $this->title(t('Registration')); // Create a model to save configuration settings $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $registrationOptions = array('Garden.Registration.Method' => 'Captcha', 'Garden.Registration.InviteExpiration', 'Garden.Registration.ConfirmEmail'); if ($manageCaptcha = c('Garden.Registration.ManageCaptcha', true)) { $registrationOptions[] = 'Garden.Registration.CaptchaPrivateKey'; $registrationOptions[] = 'Garden.Registration.CaptchaPublicKey'; } $this->setData('_ManageCaptcha', $manageCaptcha); $ConfigurationModel->setField($registrationOptions); // Set the model on the forms. $this->Form->setModel($ConfigurationModel); // Load roles with sign-in permission $RoleModel = new RoleModel(); $this->RoleData = $RoleModel->getByPermission('Garden.SignIn.Allow'); $this->setData('_Roles', array_column($this->RoleData->resultArray(), 'Name', 'RoleID')); // Get currently selected InvitationOptions $this->ExistingRoleInvitations = Gdn::config('Garden.Registration.InviteRoles'); if (is_array($this->ExistingRoleInvitations) === false) { $this->ExistingRoleInvitations = array(); } // Get the currently selected Expiration Length $this->InviteExpiration = Gdn::config('Garden.Registration.InviteExpiration', ''); // Registration methods. $this->RegistrationMethods = array('Captcha' => "New users fill out a simple form and are granted access immediately.", 'Approval' => "New users are reviewed and approved by an administrator (that's you!).", 'Invitation' => "Existing members send invitations to new members.", 'Connect' => "New users are only registered through SSO plugins."); // Options for how many invitations a role can send out per month. $this->InvitationOptions = array('0' => t('None'), '1' => '1', '2' => '2', '5' => '5', '-1' => t('Unlimited')); // Options for when invitations should expire. $this->InviteExpirationOptions = array('1 week' => t('1 week after being sent'), '2 weeks' => t('2 weeks after being sent'), '1 month' => t('1 month after being sent'), 'FALSE' => t('never')); if ($this->Form->authenticatedPostBack() === false) { $this->Form->setData($ConfigurationModel->Data); } else { // Define some validation rules for the fields being saved $ConfigurationModel->Validation->applyRule('Garden.Registration.Method', 'Required'); // Define the Garden.Registration.RoleInvitations setting based on the postback values $InvitationRoleIDs = $this->Form->getValue('InvitationRoleID'); $InvitationCounts = $this->Form->getValue('InvitationCount'); $this->ExistingRoleInvitations = arrayCombine($InvitationRoleIDs, $InvitationCounts); $ConfigurationModel->forceSetting('Garden.Registration.InviteRoles', $this->ExistingRoleInvitations); // Event hook $this->EventArguments['ConfigurationModel'] =& $ConfigurationModel; $this->fireEvent('BeforeRegistrationUpdate'); // Save! if ($this->Form->save() !== false) { $this->informMessage(t("Your settings have been saved.")); if ($RedirectUrl != '') { $this->RedirectUrl = $RedirectUrl; } } } $this->render(); }