/** * Method to register a user. * * @return boolean True on success, false on failure. * * @since 1.6 * @throws \Exception */ public function register() { // Check for request forgeries. $this->checkToken(); // If registration is disabled - Redirect to login page. if (ComponentHelper::getParams('com_users')->get('allowUserRegistration') == 0) { $this->setRedirect(Route::_('index.php?option=com_users&view=login', false)); return false; } $app = $this->app; /** @var \Joomla\Component\Users\Site\Model\RegistrationModel $model */ $model = $this->getModel('Registration', 'Site'); // Get the user data. $requestData = $this->input->post->get('jform', array(), 'array'); // Validate the posted data. $form = $model->getForm(); if (!$form) { throw new \Exception($model->getError(), 500); } $data = $model->validate($form, $requestData); // Check for validation errors. if ($data === false) { // Get the validation messages. $errors = $model->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof \Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'error'); } else { $app->enqueueMessage($errors[$i], 'error'); } } // Save the data in the session. $app->setUserState('com_users.registration.data', $requestData); // Redirect back to the registration screen. $this->setRedirect(Route::_('index.php?option=com_users&view=registration', false)); return false; } // Attempt to save the data. $return = $model->register($data); // Check for errors. if ($return === false) { // Save the data in the session. $app->setUserState('com_users.registration.data', $data); // Redirect back to the edit screen. $this->setMessage($model->getError(), 'error'); $this->setRedirect(Route::_('index.php?option=com_users&view=registration', false)); return false; } // Flush the data from the session. $app->setUserState('com_users.registration.data', null); // Redirect to the profile screen. if ($return === 'adminactivate') { $this->setMessage(Text::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY')); $this->setRedirect(Route::_('index.php?option=com_users&view=registration&layout=complete', false)); } elseif ($return === 'useractivate') { $this->setMessage(Text::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE')); $this->setRedirect(Route::_('index.php?option=com_users&view=registration&layout=complete', false)); } else { $this->setMessage(Text::_('COM_USERS_REGISTRATION_SAVE_SUCCESS')); $this->setRedirect(Route::_('index.php?option=com_users&view=login', false)); } return true; }