You've already forked joomla_test
first commit
This commit is contained in:
1
components/com_users/controllers/index.html
Normal file
1
components/com_users/controllers/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
198
components/com_users/controllers/profile.php
Normal file
198
components/com_users/controllers/profile.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 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';
|
||||
|
||||
/**
|
||||
* Profile controller class for Users.
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersControllerProfile extends UsersController
|
||||
{
|
||||
/**
|
||||
* Method to check out a user for editing and redirect to the edit form.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$user = JFactory::getUser();
|
||||
$loginUserId = (int) $user->get('id');
|
||||
|
||||
// Get the previous user id (if any) and the current user id.
|
||||
$previousId = (int) $app->getUserState('com_users.edit.profile.id');
|
||||
$userId = $this->input->getInt('user_id', null, 'array');
|
||||
|
||||
// Check if the user is trying to edit another users profile.
|
||||
if ($userId != $loginUserId)
|
||||
{
|
||||
JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the user id for the user to edit in the session.
|
||||
$app->setUserState('com_users.edit.profile.id', $userId);
|
||||
|
||||
// Get the model.
|
||||
$model = $this->getModel('Profile', 'UsersModel');
|
||||
|
||||
// Check out the user.
|
||||
if ($userId)
|
||||
{
|
||||
$model->checkout($userId);
|
||||
}
|
||||
|
||||
// Check in the previous user.
|
||||
if ($previousId)
|
||||
{
|
||||
$model->checkin($previousId);
|
||||
}
|
||||
|
||||
// Redirect to the edit screen.
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save a user's profile data.
|
||||
*
|
||||
* @return void
|
||||
* @since 1.6
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$model = $this->getModel('Profile', 'UsersModel');
|
||||
$user = JFactory::getUser();
|
||||
$userId = (int) $user->get('id');
|
||||
|
||||
// Get the user data.
|
||||
$data = $app->input->post->get('jform', array(), 'array');
|
||||
|
||||
// Force the ID to this user.
|
||||
$data['id'] = $userId;
|
||||
|
||||
// Validate the posted data.
|
||||
$form = $model->getForm();
|
||||
if (!$form)
|
||||
{
|
||||
JError::raiseError(500, $model->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the posted data.
|
||||
$data = $model->validate($form, $data);
|
||||
|
||||
// Check for 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(), 'warning');
|
||||
} else {
|
||||
$app->enqueueMessage($errors[$i], 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
// Save the data in the session.
|
||||
$app->setUserState('com_users.edit.profile.data', $data);
|
||||
|
||||
// Redirect back to the edit screen.
|
||||
$userId = (int) $app->getUserState('com_users.edit.profile.id');
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id='.$userId, false));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attempt to save the data.
|
||||
$return = $model->save($data);
|
||||
|
||||
// Check for errors.
|
||||
if ($return === false)
|
||||
{
|
||||
// Save the data in the session.
|
||||
$app->setUserState('com_users.edit.profile.data', $data);
|
||||
|
||||
// Redirect back to the edit screen.
|
||||
$userId = (int) $app->getUserState('com_users.edit.profile.id');
|
||||
$this->setMessage(JText::sprintf('COM_USERS_PROFILE_SAVE_FAILED', $model->getError()), 'warning');
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id='.$userId, false));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Redirect the user and adjust session state based on the chosen task.
|
||||
switch ($this->getTask())
|
||||
{
|
||||
case 'apply':
|
||||
// Check out the profile.
|
||||
$app->setUserState('com_users.edit.profile.id', $return);
|
||||
$model->checkout($return);
|
||||
|
||||
// Redirect back to the edit screen.
|
||||
$this->setMessage(JText::_('COM_USERS_PROFILE_SAVE_SUCCESS'));
|
||||
$this->setRedirect(JRoute::_(($redirect = $app->getUserState('com_users.edit.profile.redirect')) ? $redirect : 'index.php?option=com_users&view=profile&layout=edit&hidemainmenu=1', false));
|
||||
break;
|
||||
|
||||
default:
|
||||
// Check in the profile.
|
||||
$userId = (int) $app->getUserState('com_users.edit.profile.id');
|
||||
if ($userId)
|
||||
{
|
||||
$model->checkin($userId);
|
||||
}
|
||||
|
||||
// Clear the profile id from the session.
|
||||
$app->setUserState('com_users.edit.profile.id', null);
|
||||
|
||||
// Redirect to the list screen.
|
||||
$this->setMessage(JText::_('COM_USERS_PROFILE_SAVE_SUCCESS'));
|
||||
$this->setRedirect(JRoute::_(($redirect = $app->getUserState('com_users.edit.profile.redirect')) ? $redirect : 'index.php?option=com_users&view=profile&user_id='.$return, false));
|
||||
break;
|
||||
}
|
||||
|
||||
// Flush the data from the session.
|
||||
$app->setUserState('com_users.edit.profile.data', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that allows child controller access to model data after the data has been saved.
|
||||
*
|
||||
* @param JModelLegacy $model The data model object.
|
||||
* @param array $validData The validated data.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.1
|
||||
*/
|
||||
protected function postSaveHook(JModelLegacy $model, $validData = array())
|
||||
{
|
||||
$item = $model->getData();
|
||||
$tags = $validData['tags'];
|
||||
|
||||
if ($tags)
|
||||
{
|
||||
$item->tags = new JHelperTags;
|
||||
$item->tags->getTagIds($item->id, 'com_users.user');
|
||||
$item->metadata['tags'] = $item->tags;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
190
components/com_users/controllers/registration.php
Normal file
190
components/com_users/controllers/registration.php
Normal file
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 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 UsersControllerRegistration extends UsersController
|
||||
{
|
||||
/**
|
||||
* Method to activate a user.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function activate()
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
$input = JFactory::getApplication()->input;
|
||||
$uParams = JComponentHelper::getParams('com_users');
|
||||
|
||||
// If the user is logged in, return them back to the homepage.
|
||||
if ($user->get('id'))
|
||||
{
|
||||
$this->setRedirect('index.php');
|
||||
return true;
|
||||
}
|
||||
|
||||
// If user registration or account activation is disabled, throw a 403.
|
||||
if ($uParams->get('useractivation') == 0 || $uParams->get('allowUserRegistration') == 0)
|
||||
{
|
||||
JError::raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$model = $this->getModel('Registration', 'UsersModel');
|
||||
$token = $input->getAlnum('token');
|
||||
|
||||
// Check that the token is in a valid format.
|
||||
if ($token === null || strlen($token) !== 32)
|
||||
{
|
||||
JError::raiseError(403, JText::_('JINVALID_TOKEN'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attempt to activate the user.
|
||||
$return = $model->activate($token);
|
||||
|
||||
// Check for errors.
|
||||
if ($return === false)
|
||||
{
|
||||
// Redirect back to the homepage.
|
||||
$this->setMessage(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $model->getError()), 'warning');
|
||||
$this->setRedirect('index.php');
|
||||
return false;
|
||||
}
|
||||
|
||||
$useractivation = $uParams->get('useractivation');
|
||||
|
||||
// Redirect to the login screen.
|
||||
if ($useractivation == 0)
|
||||
{
|
||||
$this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
|
||||
}
|
||||
elseif ($useractivation == 1)
|
||||
{
|
||||
$this->setMessage(JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS'));
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
|
||||
}
|
||||
elseif ($return->getParam('activate'))
|
||||
{
|
||||
$this->setMessage(JText::_('COM_USERS_REGISTRATION_VERIFY_SUCCESS'));
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setMessage(JText::_('COM_USERS_REGISTRATION_ADMINACTIVATE_SUCCESS'));
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to register a user.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
// If registration is disabled - Redirect to login page.
|
||||
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');
|
||||
|
||||
// Get the user data.
|
||||
$requestData = $this->input->post->get('jform', array(), 'array');
|
||||
|
||||
// Validate the posted data.
|
||||
$form = $model->getForm();
|
||||
if (!$form)
|
||||
{
|
||||
JError::raiseError(500, $model->getError());
|
||||
return false;
|
||||
}
|
||||
$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(), 'warning');
|
||||
} else {
|
||||
$app->enqueueMessage($errors[$i], 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
// Save the data in the session.
|
||||
$app->setUserState('com_users.registration.data', $requestData);
|
||||
|
||||
// Redirect back to the registration screen.
|
||||
$this->setRedirect(JRoute::_('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(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $model->getError()), 'warning');
|
||||
$this->setRedirect(JRoute::_('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(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'));
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
|
||||
} elseif ($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;
|
||||
}
|
||||
}
|
67
components/com_users/controllers/remind.php
Normal file
67
components/com_users/controllers/remind.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 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';
|
||||
|
||||
/**
|
||||
* Reset controller class for Users.
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersControllerRemind extends UsersController
|
||||
{
|
||||
/**
|
||||
* Method to request a username reminder.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function remind()
|
||||
{
|
||||
// Check the request token.
|
||||
JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
$model = $this->getModel('Remind', 'UsersModel');
|
||||
$data = $this->input->post->get('jform', array(), 'array');
|
||||
|
||||
// Submit the password reset request.
|
||||
$return = $model->processRemindRequest($data);
|
||||
|
||||
// Check for a hard error.
|
||||
if ($return == false)
|
||||
{
|
||||
// The request 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 request form.
|
||||
$message = JText::sprintf('COM_USERS_REMIND_REQUEST_FAILED', $model->getError());
|
||||
$this->setRedirect(JRoute::_($route, false), $message, 'notice');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The request succeeded.
|
||||
// Get the route to the next page.
|
||||
$itemid = UsersHelperRoute::getRemindRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=login'.$itemid;
|
||||
|
||||
// Proceed to step two.
|
||||
$message = JText::_('COM_USERS_REMIND_REQUEST_SUCCESS');
|
||||
$this->setRedirect(JRoute::_($route, false), $message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
213
components/com_users/controllers/reset.php
Normal file
213
components/com_users/controllers/reset.php
Normal file
@ -0,0 +1,213 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 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';
|
||||
|
||||
/**
|
||||
* Reset controller class for Users.
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersControllerReset extends UsersController
|
||||
{
|
||||
/**
|
||||
* Method to request a password reset.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function request()
|
||||
{
|
||||
// Check the request token.
|
||||
JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$model = $this->getModel('Reset', 'UsersModel');
|
||||
$data = $this->input->post->get('jform', array(), 'array');
|
||||
|
||||
// Submit the password reset request.
|
||||
$return = $model->processResetRequest($data);
|
||||
|
||||
// Check for a hard error.
|
||||
if ($return instanceof Exception)
|
||||
{
|
||||
// Get the error message to display.
|
||||
if ($app->getCfg('error_reporting'))
|
||||
{
|
||||
$message = $return->getMessage();
|
||||
} else {
|
||||
$message = JText::_('COM_USERS_RESET_REQUEST_ERROR');
|
||||
}
|
||||
|
||||
// Get the route to the next page.
|
||||
$itemid = UsersHelperRoute::getResetRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=reset'.$itemid;
|
||||
|
||||
// Go back to the request form.
|
||||
$this->setRedirect(JRoute::_($route, false), $message, 'error');
|
||||
return false;
|
||||
} elseif ($return === false)
|
||||
{
|
||||
// The request failed.
|
||||
// Get the route to the next page.
|
||||
$itemid = UsersHelperRoute::getResetRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=reset'.$itemid;
|
||||
|
||||
// Go back to the request form.
|
||||
$message = JText::sprintf('COM_USERS_RESET_REQUEST_FAILED', $model->getError());
|
||||
$this->setRedirect(JRoute::_($route, false), $message, 'notice');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The request succeeded.
|
||||
// Get the route to the next page.
|
||||
$itemid = UsersHelperRoute::getResetRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
|
||||
|
||||
// Proceed to step two.
|
||||
$this->setRedirect(JRoute::_($route, false));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to confirm the password request.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.6
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
// Check the request token.
|
||||
JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$model = $this->getModel('Reset', 'UsersModel');
|
||||
$data = $this->input->get('jform', array(), 'array');
|
||||
|
||||
// Confirm the password reset request.
|
||||
$return = $model->processResetConfirm($data);
|
||||
|
||||
// Check for a hard error.
|
||||
if ($return instanceof Exception)
|
||||
{
|
||||
// Get the error message to display.
|
||||
if ($app->getCfg('error_reporting'))
|
||||
{
|
||||
$message = $return->getMessage();
|
||||
} else {
|
||||
$message = JText::_('COM_USERS_RESET_CONFIRM_ERROR');
|
||||
}
|
||||
|
||||
// Get the route to the next page.
|
||||
$itemid = UsersHelperRoute::getResetRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
|
||||
|
||||
// Go back to the confirm form.
|
||||
$this->setRedirect(JRoute::_($route, false), $message, 'error');
|
||||
return false;
|
||||
} elseif ($return === false)
|
||||
{
|
||||
// Confirm failed.
|
||||
// Get the route to the next page.
|
||||
$itemid = UsersHelperRoute::getResetRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
|
||||
|
||||
// Go back to the confirm form.
|
||||
$message = JText::sprintf('COM_USERS_RESET_CONFIRM_FAILED', $model->getError());
|
||||
$this->setRedirect(JRoute::_($route, false), $message, 'notice');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Confirm succeeded.
|
||||
// Get the route to the next page.
|
||||
$itemid = UsersHelperRoute::getResetRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
|
||||
|
||||
// Proceed to step three.
|
||||
$this->setRedirect(JRoute::_($route, false));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to complete the password reset process.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function complete()
|
||||
{
|
||||
// Check for request forgeries
|
||||
JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$model = $this->getModel('Reset', 'UsersModel');
|
||||
$data = $this->input->post->get('jform', array(), 'array');
|
||||
|
||||
// Complete the password reset request.
|
||||
$return = $model->processResetComplete($data);
|
||||
|
||||
// Check for a hard error.
|
||||
if ($return instanceof Exception)
|
||||
{
|
||||
// Get the error message to display.
|
||||
if ($app->getCfg('error_reporting'))
|
||||
{
|
||||
$message = $return->getMessage();
|
||||
} else {
|
||||
$message = JText::_('COM_USERS_RESET_COMPLETE_ERROR');
|
||||
}
|
||||
|
||||
// Get the route to the next page.
|
||||
$itemid = UsersHelperRoute::getResetRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=reset&layout=complete'.$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::getResetRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
|
||||
$route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
|
||||
|
||||
// Go back to the complete form.
|
||||
$message = JText::sprintf('COM_USERS_RESET_COMPLETE_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_RESET_COMPLETE_SUCCESS');
|
||||
$this->setRedirect(JRoute::_($route, false), $message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
246
components/com_users/controllers/user.php
Normal file
246
components/com_users/controllers/user.php
Normal file
@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 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()
|
||||
{
|
||||
JSession::checkToken('post') or jexit(JText::_('JInvalid_Token'));
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// Populate the data array:
|
||||
$data = array();
|
||||
$data['return'] = base64_decode($app->input->post->get('return', '', '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';
|
||||
}
|
||||
|
||||
// Set the return URL in the user state to allow modification by plugins
|
||||
$app->setUserState('users.login.form.return', $data['return']);
|
||||
|
||||
// Get the log in options.
|
||||
$options = array();
|
||||
$options['remember'] = $this->input->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.
|
||||
if (true === $app->login($credentials, $options))
|
||||
{
|
||||
// Success
|
||||
$app->setUserState('users.login.form.data', array());
|
||||
$app->redirect(JRoute::_($app->getUserState('users.login.form.return'), false));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Login failed !
|
||||
$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()
|
||||
{
|
||||
JSession::checkToken('request') or jexit(JText::_('JInvalid_Token'));
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// Perform the log in.
|
||||
$error = $app->logout();
|
||||
|
||||
// Check if the log out succeeded.
|
||||
if (!($error instanceof Exception))
|
||||
{
|
||||
// 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()
|
||||
{
|
||||
JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
// Get the form data.
|
||||
$data = $this->input->post->get('user', array(), '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 ($errors[$i] instanceof Exception)
|
||||
{
|
||||
$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.
|
||||
JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$model = $this->getModel('User', 'UsersModel');
|
||||
$data = $this->input->post->get('jform', array(), 'array');
|
||||
|
||||
// Submit the username remind request.
|
||||
$return = $model->processRemindRequest($data);
|
||||
|
||||
// Check for a hard error.
|
||||
if ($return instanceof Exception)
|
||||
{
|
||||
// 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
|
||||
JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user