Source for file registration.php

Documentation is available at registration.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_users
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. require_once JPATH_COMPONENT.'/controller.php';
  13.  
  14. /**
  15.  * Registration controller class for Users.
  16.  *
  17.  * @package     Joomla.Site
  18.  * @subpackage  com_users
  19.  * @since       1.6
  20.  */
  21. {
  22.     /**
  23.      * Method to activate a user.
  24.      *
  25.      * @return  boolean  True on success, false on failure.
  26.      * @since   1.6
  27.      */
  28.     public function activate()
  29.     {
  30.         $user  JFactory::getUser();
  31.         $input JFactory::getApplication()->input;
  32.         $uParams JComponentHelper::getParams('com_users');
  33.  
  34.         // If the user is logged in, return them back to the homepage.
  35.         if ($user->get('id'))
  36.         {
  37.             $this->setRedirect('index.php');
  38.             return true;
  39.         }
  40.  
  41.         // If user registration or account activation is disabled, throw a 403.
  42.         if ($uParams->get('useractivation'== || $uParams->get('allowUserRegistration'== 0)
  43.         {
  44.             JError::raiseError(403JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
  45.             return false;
  46.         }
  47.  
  48.         $model $this->getModel('Registration''UsersModel');
  49.         $token $input->getAlnum('token');
  50.  
  51.         // Check that the token is in a valid format.
  52.         if ($token === null || strlen($token!== 32)
  53.         {
  54.             JError::raiseError(403JText::_('JINVALID_TOKEN'));
  55.             return false;
  56.         }
  57.  
  58.         // Attempt to activate the user.
  59.         $return $model->activate($token);
  60.  
  61.         // Check for errors.
  62.         if ($return === false)
  63.         {
  64.             // Redirect back to the homepage.
  65.             $this->setMessage(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED'$model->getError())'warning');
  66.             $this->setRedirect('index.php');
  67.             return false;
  68.         }
  69.  
  70.         $useractivation $uParams->get('useractivation');
  71.  
  72.         // Redirect to the login screen.
  73.         if ($useractivation == 0)
  74.         {
  75.             $this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
  76.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=login'false));
  77.         }
  78.         elseif ($useractivation == 1)
  79.         {
  80.             $this->setMessage(JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS'));
  81.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=login'false));
  82.         }
  83.         elseif ($return->getParam('activate'))
  84.         {
  85.             $this->setMessage(JText::_('COM_USERS_REGISTRATION_VERIFY_SUCCESS'));
  86.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete'false));
  87.         }
  88.         else
  89.         {
  90.             $this->setMessage(JText::_('COM_USERS_REGISTRATION_ADMINACTIVATE_SUCCESS'));
  91.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete'false));
  92.         }
  93.         return true;
  94.     }
  95.  
  96.     /**
  97.      * Method to register a user.
  98.      *
  99.      * @return  boolean  True on success, false on failure.
  100.      * @since   1.6
  101.      */
  102.     public function register()
  103.     {
  104.         // Check for request forgeries.
  105.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  106.  
  107.         // If registration is disabled - Redirect to login page.
  108.         if (JComponentHelper::getParams('com_users')->get('allowUserRegistration'== 0)
  109.         {
  110.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=login'false));
  111.             return false;
  112.         }
  113.  
  114.         $app    JFactory::getApplication();
  115.         $model    $this->getModel('Registration''UsersModel');
  116.  
  117.         // Get the user data.
  118.         $requestData $this->input->post->get('jform'array()'array');
  119.  
  120.         // Validate the posted data.
  121.         $form    $model->getForm();
  122.         if (!$form)
  123.         {
  124.             JError::raiseError(500$model->getError());
  125.             return false;
  126.         }
  127.         $data    $model->validate($form$requestData);
  128.  
  129.         // Check for validation errors.
  130.         if ($data === false)
  131.         {
  132.             // Get the validation messages.
  133.             $errors    $model->getErrors();
  134.  
  135.             // Push up to three validation messages out to the user.
  136.             for ($i 0$n count($errors)$i $n && $i 3$i++)
  137.             {
  138.                 if ($errors[$iinstanceof Exception)
  139.                 {
  140.                     $app->enqueueMessage($errors[$i]->getMessage()'warning');
  141.                 else {
  142.                     $app->enqueueMessage($errors[$i]'warning');
  143.                 }
  144.             }
  145.  
  146.             // Save the data in the session.
  147.             $app->setUserState('com_users.registration.data'$requestData);
  148.  
  149.             // Redirect back to the registration screen.
  150.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration'false));
  151.             return false;
  152.         }
  153.  
  154.         // Attempt to save the data.
  155.         $return    $model->register($data);
  156.  
  157.         // Check for errors.
  158.         if ($return === false)
  159.         {
  160.             // Save the data in the session.
  161.             $app->setUserState('com_users.registration.data'$data);
  162.  
  163.             // Redirect back to the edit screen.
  164.             $this->setMessage(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED'$model->getError())'warning');
  165.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration'false));
  166.             return false;
  167.         }
  168.  
  169.         // Flush the data from the session.
  170.         $app->setUserState('com_users.registration.data'null);
  171.  
  172.         // Redirect to the profile screen.
  173.         if ($return === 'adminactivate'){
  174.             $this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'));
  175.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete'false));
  176.         elseif ($return === 'useractivate')
  177.         {
  178.             $this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'));
  179.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete'false));
  180.         }
  181.         else
  182.         {
  183.             $this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
  184.             $this->setRedirect(JRoute::_('index.php?option=com_users&view=login'false));
  185.         }
  186.  
  187.         return true;
  188.     }
  189. }

Documentation generated on Tue, 19 Nov 2013 15:11:42 +0100 by phpDocumentor 1.4.3