- md5
- 5925142506a429741786bb708d1dfbda
- sha1
- 9c3851d5f06f3c5b5f6d7b18bd97f7adac7b52d3
- sha256
- 71ce1c719a3c8cff8006a6520dcd7780f24a37f30f8fbcc648aacbb887a2aeb9
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
<?php
/**
* @version $Id: user.php 22338 2011-11-04 17:24:53Z github_bot $
* @package Joomla.Site
* @subpackage com_users
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
require_once JPATH_COMPONENT.'/controller.php';
/**
* Registration controller class for Users.
*
* @package Joomla.Site
* @subpackage com_users
* @since 1.6
*/
class UsersControllerUser extends UsersController
{
/**
* Method to log in a user.
*
* @since 1.6
*/
public function login()
{
JRequest::checkToken('post') or jexit(JText::_('JInvalid_Token'));
$app = JFactory::getApplication();
// Populate the data array:
$data = array();
$data['return'] = base64_decode(JRequest::getVar('return', '', 'POST', 'BASE64'));
$data['username'] = JRequest::getVar('username', '', 'method', 'username');
$data['password'] = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
// Set the return URL if empty.
if (empty($data['return'])) {
$data['return'] = 'index.php?option=com_users&view=profile';
}
// Get the log in options.
$options = array();
$options['remember'] = JRequest::getBool('remember', false);
$options['return'] = $data['return'];
// Get the log in credentials.
$credentials = array();
$credentials['username'] = $data['username'];
$credentials['password'] = $data['password'];
// Perform the log in.
$error = $app->login($credentials, $options);
// Check if the log in succeeded.
if (!JError::isError($error)) {
$app->setUserState('users.login.form.data', array());
$app->redirect(JRoute::_($data['return'], false));
} else {
$data['remember'] = (int)$options['remember'];
$app->setUserState('users.login.form.data', $data);
$app->redirect(JRoute::_('index.php?option=com_users&view=login', false));
}
}
/**
* Method to log out a user.
*
* @since 1.6
*/
public function logout()
{
JRequest::checkToken('default') or jexit(JText::_('JInvalid_Token'));
$app = JFactory::getApplication();
// Perform the log in.
$error = $app->logout();
// Check if the log out succeeded.
if (!JError::isError($error)) {
// Get the return url from the request and validate that it is internal.
$return = JRequest::getVar('return', '', 'method', 'base64');
$return = base64_decode($return);
if (!JURI::isInternal($return)) {
$return = '';
}
// Redirect the user.
$app->redirect(JRoute::_($return, false));
} else {
$app->redirect(JRoute::_('index.php?option=com_users&view=login', false));
}
}
/**
* Method to register a user.
*
* @since 1.6
*/
public function register()
{
JRequest::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
// Get the form data.
$data = JRequest::getVar('user', array(), 'post', 'array');
// Get the model and validate the data.
$model = $this->getModel('Registration', 'UsersModel');
$return = $model->validate($data);
// Check for errors.
if ($return === false) {
// Get the validation messages.
$app = &JFactory::getApplication();
$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 (JError::isError($errors[$i])) {
$app->enqueueMessage($errors[$i]->getMessage(), 'notice');
} else {
$app->enqueueMessage($errors[$i], 'notice');
}
}
// Save the data in the session.
$app->setUserState('users.registration.form.data', $data);
// Redirect back to the registration form.
$this->setRedirect('index.php?option=com_users&view=registration');
return false;
}
// Finish the registration.
$return = $model->register($data);
// Check for errors.
if ($return === false) {
// Save the data in the session.
$app->setUserState('users.registration.form.data', $data);
// Redirect back to the registration form.
$message = JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $model->getError());
$this->setRedirect('index.php?option=com_users&view=registration', $message, 'error');
return false;
}
// Flush the data from the session.
$app->setUserState('users.registration.form.data', null);
exit;
}
/**
* Method to login a user.
*
* @since 1.6
*/
public function remind()
{
// Check the request token.
JRequest::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
$model = $this->getModel('User', 'UsersModel');
$data = JRequest::getVar('jform', array(), 'post', 'array');
// Submit the username remind request.
$return = $model->processRemindRequest($data);
// Check for a hard error.
if (JError::isError($return)) {
// Get the error message to display.
if ($app->getCfg('error_reporting')) {
$message = $return->getMessage();
} else {
$message = JText::_('COM_USERS_REMIND_REQUEST_ERROR');
}
// Get the route to the next page.
$itemid = UsersHelperRoute::getRemindRoute();
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
$route = 'index.php?option=com_users&view=remind'.$itemid;
// Go back to the complete form.
$this->setRedirect(JRoute::_($route, false), $message, 'error');
return false;
} elseif ($return === false) {
// Complete failed.
// Get the route to the next page.
$itemid = UsersHelperRoute::getRemindRoute();
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
$route = 'index.php?option=com_users&view=remind'.$itemid;
// Go back to the complete form.
$message = JText::sprintf('COM_USERS_REMIND_REQUEST_FAILED', $model->getError());
$this->setRedirect(JRoute::_($route, false), $message, 'notice');
return false;
} else {
// Complete succeeded.
// Get the route to the next page.
$itemid = UsersHelperRoute::getLoginRoute();
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
$route = 'index.php?option=com_users&view=login'.$itemid;
// Proceed to the login form.
$message = JText::_('COM_USERS_REMIND_REQUEST_SUCCESS');
$this->setRedirect(JRoute::_($route, false), $message);
return true;
}
}
/**
* Method to login a user.
*
* @since 1.6
*/
public function resend()
{
// Check for request forgeries
JRequest::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
}
}
The same content is in 3 releases, Joomla 1.7.3 to 1.7.5. See them all, or every version of this file.