english/components/com_users/controllers/registration.php
/**
	 * Method to register a user.
	 *
	 * @return	boolean		True on success, false on failure.
	 * @since	1.6
	 */
Method to register a user.
@return      boolean         True on success, false on failure.
Method to register a user . @return boolean True on success false on failure .
public function register()
	{
		JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
		if(JComponentHelper::getParams('com_users')->get('allowUserRegistration') == 0) {
			$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
			return false;
		}
		$app	= JFactory::getApplication();
		$model	= $this->getModel('Registration', 'UsersModel');
		$requestData = JRequest::getVar('jform', array(), 'post', 'array');
		$form	= $model->getForm();
		if (!$form) {
			JError::raiseError(500, $model->getError());
			return false;
		}
		$data	= $model->validate($form, $requestData);
		if ($data === false) {
			$errors	= $model->getErrors();
			for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
				if (JError::isError($errors[$i])) {
					$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
				} else {
					$app->enqueueMessage($errors[$i], 'warning');
				}
			}
			$app->setUserState('com_users.registration.data', $requestData);
			$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration', false));
			return false;
		}
		$return	= $model->register($data);
		if ($return === false) {
			$app->setUserState('com_users.registration.data', $data);
			$this->setMessage(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $model->getError()), 'warning');
			$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration', false));
			return false;
		}
		$app->setUserState('com_users.registration.data', null);
		if ($return === 'adminactivate'){
			$this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'));
			$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
		} else if ($return === 'useractivate') {
			$this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'));
			$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
		} else {
			$this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
			$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
		}
		return true;
	}
public function register ( ) { JRequest :: checkToken ( ) or jexit ( JText :: _ ( 'JINVALID_TOKEN' ) ) ; if ( JComponentHelper :: getParams ( 'com_users' ) -> get ( 'allowUserRegistration' ) == 0 ) { $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_users&view=login' , false ) ) ; return false ; } $ app = JFactory :: getApplication ( ) ; $ model = $ this -> getModel ( 'Registration' , 'UsersModel' ) ; $ requestData = JRequest :: getVar ( 'jform' , array ( ) , 'post' , 'array' ) ; $ form = $ model -> getForm ( ) ; if ( ! $ form ) { JError :: raiseError ( 500 , $ model -> getError ( ) ) ; return false ; } $ data = $ model -> validate ( $ form , $ requestData ) ; if ( $ data === false ) { $ errors = $ model -> getErrors ( ) ; for ( $ i = 0 , $ n = count ( $ errors ) ; $ i < $ n && $ i < 3 ; $ i ++ ) { if ( JError :: isError ( $ errors [ $ i ] ) ) { $ app -> enqueueMessage ( $ errors [ $ i ] -> getMessage ( ) , 'warning' ) ; } else { $ app -> enqueueMessage ( $ errors [ $ i ] , 'warning' ) ; } } $ app -> setUserState ( 'com_users.registration.data' , $ requestData ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_users&view=registration' , false ) ) ; return false ; } $ return = $ model -> register ( $ data ) ; if ( $ return === false ) { $ app -> setUserState ( 'com_users.registration.data' , $ data ) ; $ this -> setMessage ( JText :: sprintf ( 'COM_USERS_REGISTRATION_SAVE_FAILED' , $ model -> getError ( ) ) , 'warning' ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_users&view=registration' , false ) ) ; return false ; } $ app -> setUserState ( 'com_users.registration.data' , null ) ; if ( $ return === 'adminactivate' ) { $ this -> setMessage ( JText :: _ ( 'COM_USERS_REGISTRATION_COMPLETE_VERIFY' ) ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_users&view=registration&layout=complete' , false ) ) ; } else if ( $ return === 'useractivate' ) { $ this -> setMessage ( JText :: _ ( 'COM_USERS_REGISTRATION_COMPLETE_ACTIVATE' ) ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_users&view=registration&layout=complete' , false ) ) ; } else { $ this -> setMessage ( JText :: _ ( 'COM_USERS_REGISTRATION_SAVE_SUCCESS' ) ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_users&view=login' , false ) ) ; } return true ; }
Method to register a user.
Method to register a user .
// Check for request forgeries. // If registration is disabled - Redirect to login page. // Initialise variables. // Get the user data. // Validate the posted data. // Check for validation errors. // Get the validation messages. // Push up to three validation messages out to the user. // Save the data in the session. // Redirect back to the registration screen. // Attempt to save the data. // Check for errors. // Save the data in the session. // Redirect back to the edit screen. // Flush the data from the session. // Redirect to the profile screen.