Source for file user.php

Documentation is available at user.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 log in a user.
  24.      *
  25.      * @since   1.6
  26.      */
  27.     public function login()
  28.     {
  29.         JSession::checkToken('post'or jexit(JText::_('JInvalid_Token'));
  30.  
  31.         $app JFactory::getApplication();
  32.  
  33.         // Populate the data array:
  34.         $data array();
  35.         $data['return'base64_decode($app->input->post->get('return''''BASE64'));
  36.         $data['username'JRequest::getVar('username''''method''username');
  37.         $data['password'JRequest::getString('password''''post'JREQUEST_ALLOWRAW);
  38.         $data['secretkey'JRequest::getString('secretkey''');
  39.  
  40.         // Set the return URL if empty.
  41.         if (empty($data['return']))
  42.         {
  43.             $data['return''index.php?option=com_users&view=profile';
  44.         }
  45.  
  46.         // Set the return URL in the user state to allow modification by plugins
  47.         $app->setUserState('users.login.form.return'$data['return']);
  48.  
  49.         // Get the log in options.
  50.         $options array();
  51.         $options['remember'$this->input->getBool('remember'false);
  52.         $options['return'$data['return'];
  53.  
  54.         // Get the log in credentials.
  55.         $credentials array();
  56.         $credentials['username']  $data['username'];
  57.         $credentials['password']  $data['password'];
  58.         $credentials['secretkey'$data['secretkey'];
  59.  
  60.         // Perform the log in.
  61.         if (true === $app->login($credentials$options))
  62.         {
  63.             // Success
  64.             if ($options['remember'true)
  65.             {
  66.                 $app->setUserState('rememberLogin'true);
  67.             }
  68.  
  69.             $app->setUserState('users.login.form.data'array());
  70.             $app->redirect(JRoute::_($app->getUserState('users.login.form.return')false));
  71.         }
  72.         else
  73.         {
  74.             // Login failed !
  75.             $data['remember'= (int) $options['remember'];
  76.             $app->setUserState('users.login.form.data'$data);
  77.             $app->redirect(JRoute::_('index.php?option=com_users&view=login'false));
  78.         }
  79.     }
  80.  
  81.     /**
  82.      * Method to log out a user.
  83.      *
  84.      * @since   1.6
  85.      */
  86.     public function logout()
  87.     {
  88.         JSession::checkToken('request'or jexit(JText::_('JInvalid_Token'));
  89.  
  90.         $app JFactory::getApplication();
  91.  
  92.         // Perform the log in.
  93.         $error $app->logout();
  94.  
  95.         // Check if the log out succeeded.
  96.         if (!($error instanceof Exception))
  97.         {
  98.             // Get the return url from the request and validate that it is internal.
  99.             $return JRequest::getVar('return''''method''base64');
  100.             $return base64_decode($return);
  101.             if (!JUri::isInternal($return))
  102.             {
  103.                 $return '';
  104.             }
  105.  
  106.             // Redirect the user.
  107.             $app->redirect(JRoute::_($returnfalse));
  108.         }
  109.         else
  110.         {
  111.             $app->redirect(JRoute::_('index.php?option=com_users&view=login'false));
  112.         }
  113.     }
  114.  
  115.     /**
  116.      * Method to register a user.
  117.      *
  118.      * @since   1.6
  119.      */
  120.     public function register()
  121.     {
  122.         JSession::checkToken('post'or jexit(JText::_('JINVALID_TOKEN'));
  123.  
  124.         // Get the form data.
  125.         $data  $this->input->post->get('user'array()'array');
  126.  
  127.         // Get the model and validate the data.
  128.         $model  $this->getModel('Registration''UsersModel');
  129.         $return    $model->validate($data);
  130.  
  131.         // Check for errors.
  132.         if ($return === false)
  133.         {
  134.             // Get the validation messages.
  135.             $app    &JFactory::getApplication();
  136.             $errors    $model->getErrors();
  137.  
  138.             // Push up to three validation messages out to the user.
  139.             for ($i 0$n count($errors)$i $n && $i 3$i++)
  140.             {
  141.                 if ($errors[$iinstanceof Exception)
  142.                 {
  143.                     $app->enqueueMessage($errors[$i]->getMessage()'notice');
  144.                 else {
  145.                     $app->enqueueMessage($errors[$i]'notice');
  146.                 }
  147.             }
  148.  
  149.             // Save the data in the session.
  150.             $app->setUserState('users.registration.form.data'$data);
  151.  
  152.             // Redirect back to the registration form.
  153.             $this->setRedirect('index.php?option=com_users&view=registration');
  154.             return false;
  155.         }
  156.  
  157.         // Finish the registration.
  158.         $return    $model->register($data);
  159.  
  160.         // Check for errors.
  161.         if ($return === false)
  162.         {
  163.             // Save the data in the session.
  164.             $app->setUserState('users.registration.form.data'$data);
  165.  
  166.             // Redirect back to the registration form.
  167.             $message JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED'$model->getError());
  168.             $this->setRedirect('index.php?option=com_users&view=registration'$message'error');
  169.             return false;
  170.         }
  171.  
  172.         // Flush the data from the session.
  173.         $app->setUserState('users.registration.form.data'null);
  174.  
  175.         exit;
  176.     }
  177.  
  178.     /**
  179.      * Method to login a user.
  180.      *
  181.      * @since   1.6
  182.      */
  183.     public function remind()
  184.     {
  185.         // Check the request token.
  186.         JSession::checkToken('post'or jexit(JText::_('JINVALID_TOKEN'));
  187.  
  188.         $app   JFactory::getApplication();
  189.         $model $this->getModel('User''UsersModel');
  190.         $data  $this->input->post->get('jform'array()'array');
  191.  
  192.         // Submit the username remind request.
  193.         $return    $model->processRemindRequest($data);
  194.  
  195.         // Check for a hard error.
  196.         if ($return instanceof Exception)
  197.         {
  198.             // Get the error message to display.
  199.             if ($app->getCfg('error_reporting'))
  200.             {
  201.                 $message $return->getMessage();
  202.             else {
  203.                 $message JText::_('COM_USERS_REMIND_REQUEST_ERROR');
  204.             }
  205.  
  206.             // Get the route to the next page.
  207.             $itemid UsersHelperRoute::getRemindRoute();
  208.             $itemid $itemid !== null '&Itemid='.$itemid '';
  209.             $route    'index.php?option=com_users&view=remind'.$itemid;
  210.  
  211.             // Go back to the complete form.
  212.             $this->setRedirect(JRoute::_($routefalse)$message'error');
  213.             return false;
  214.         elseif ($return === false)
  215.         {
  216.             // Complete failed.
  217.             // Get the route to the next page.
  218.             $itemid UsersHelperRoute::getRemindRoute();
  219.             $itemid $itemid !== null '&Itemid='.$itemid '';
  220.             $route    'index.php?option=com_users&view=remind'.$itemid;
  221.  
  222.             // Go back to the complete form.
  223.             $message JText::sprintf('COM_USERS_REMIND_REQUEST_FAILED'$model->getError());
  224.             $this->setRedirect(JRoute::_($routefalse)$message'notice');
  225.             return false;
  226.         }
  227.         else
  228.         {
  229.             // Complete succeeded.
  230.             // Get the route to the next page.
  231.             $itemid UsersHelperRoute::getLoginRoute();
  232.             $itemid $itemid !== null '&Itemid='.$itemid '';
  233.             $route    'index.php?option=com_users&view=login'.$itemid;
  234.  
  235.             // Proceed to the login form.
  236.             $message JText::_('COM_USERS_REMIND_REQUEST_SUCCESS');
  237.             $this->setRedirect(JRoute::_($routefalse)$message);
  238.             return true;
  239.         }
  240.     }
  241.  
  242.     /**
  243.      * Method to login a user.
  244.      *
  245.      * @since   1.6
  246.      */
  247.     public function resend()
  248.     {
  249.         // Check for request forgeries
  250.         JSession::checkToken('post'or jexit(JText::_('JINVALID_TOKEN'));
  251.     }
  252. }

Documentation generated on Tue, 19 Nov 2013 15:16:18 +0100 by phpDocumentor 1.4.3