You've already forked joomla_test
first commit
This commit is contained in:
31
components/com_users/models/forms/frontend.xml
Normal file
31
components/com_users/models/forms/frontend.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fields name="params">
|
||||
<!-- Basic user account settings. -->
|
||||
<fieldset name="params" label="COM_USERS_SETTINGS_FIELDSET_LABEL">
|
||||
|
||||
<field name="editor" type="plugins" folder="editors"
|
||||
description="COM_USERS_USER_FIELD_EDITOR_DESC"
|
||||
label="COM_USERS_USER_FIELD_EDITOR_LABEL"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="timezone" type="timezone"
|
||||
label="COM_USERS_USER_FIELD_TIMEZONE_LABEL"
|
||||
description="COM_USERS_USER_FIELD_TIMEZONE_DESC"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="language" type="language"
|
||||
client="site"
|
||||
description="COM_USERS_USER_FIELD_FRONTEND_LANGUAGE_DESC"
|
||||
label="COM_USERS_USER_FIELD_FRONTEND_LANGUAGE_LABEL"
|
||||
filter="cmd"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
33
components/com_users/models/forms/frontend_admin.xml
Normal file
33
components/com_users/models/forms/frontend_admin.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fields name="params">
|
||||
<!-- Backend user account settings. -->
|
||||
<fieldset name="params" label="COM_USERS_SETTINGS_FIELDSET_LABEL">
|
||||
|
||||
<field name="admin_style" type="templatestyle"
|
||||
client="administrator"
|
||||
description="COM_USERS_USER_FIELD_BACKEND_TEMPLATE_DESC"
|
||||
label="COM_USERS_USER_FIELD_BACKEND_TEMPLATE_LABEL"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="admin_language" type="language"
|
||||
client="administrator"
|
||||
description="COM_USERS_USER_FIELD_BACKEND_LANGUAGE_DESC"
|
||||
label="COM_USERS_USER_FIELD_BACKEND_LANGUAGE_LABEL"
|
||||
filter="cmd"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="helpsite" type="helpsite"
|
||||
label="COM_USERS_USER_FIELD_HELPSITE_LABEL"
|
||||
description="COM_USERS_USER_FIELD_HELPSITE_DESC"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
1
components/com_users/models/forms/index.html
Normal file
1
components/com_users/models/forms/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
26
components/com_users/models/forms/login.xml
Normal file
26
components/com_users/models/forms/login.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="credentials"
|
||||
label="COM_USERS_LOGIN_DEFAULT_LABEL" >
|
||||
|
||||
<field name="username" type="text"
|
||||
class="validate-username"
|
||||
filter="username"
|
||||
label="COM_USERS_LOGIN_USERNAME_LABEL"
|
||||
size="25"
|
||||
required="true"
|
||||
validate="username"
|
||||
/>
|
||||
|
||||
<field name="password" type="password"
|
||||
class="validate-password"
|
||||
required="true"
|
||||
filter="raw"
|
||||
label="JGLOBAL_PASSWORD"
|
||||
size="25"
|
||||
/>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<field name="return" type="hidden" />
|
||||
</fieldset>
|
||||
</form>
|
73
components/com_users/models/forms/profile.xml
Normal file
73
components/com_users/models/forms/profile.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="core"
|
||||
label="COM_USERS_PROFILE_DEFAULT_LABEL">
|
||||
|
||||
<field name="id" type="hidden"
|
||||
filter="integer"
|
||||
/>
|
||||
|
||||
<field name="name" type="text"
|
||||
description="COM_USERS_PROFILE_NAME_DESC"
|
||||
filter="string"
|
||||
label="COM_USERS_PROFILE_NAME_LABEL"
|
||||
required="true"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field name="username" type="text"
|
||||
class="validate-username"
|
||||
description="COM_USERS_DESIRED_USERNAME"
|
||||
filter="username"
|
||||
label="COM_USERS_PROFILE_USERNAME_LABEL"
|
||||
message="COM_USERS_PROFILE_USERNAME_MESSAGE"
|
||||
required="true"
|
||||
size="30"
|
||||
validate="username"
|
||||
/>
|
||||
|
||||
<field name="password2" type="password"
|
||||
autocomplete="off"
|
||||
class="validate-password"
|
||||
description="COM_USERS_DESIRED_PASSWORD"
|
||||
field="password1"
|
||||
filter="raw"
|
||||
label="COM_USERS_PROFILE_PASSWORD1_LABEL"
|
||||
message="COM_USERS_PROFILE_PASSWORD1_MESSAGE"
|
||||
size="30"
|
||||
validate="equals"
|
||||
/>
|
||||
|
||||
<field name="password1" type="password"
|
||||
autocomplete="off"
|
||||
class="validate-password"
|
||||
description="COM_USERS_PROFILE_PASSWORD2_DESC"
|
||||
filter="raw"
|
||||
label="COM_USERS_PROFILE_PASSWORD2_LABEL"
|
||||
size="30"
|
||||
validate="password"
|
||||
/>
|
||||
|
||||
<field name="email1" type="email"
|
||||
description="COM_USERS_PROFILE_EMAIL1_DESC"
|
||||
filter="string"
|
||||
label="COM_USERS_PROFILE_EMAIL1_LABEL"
|
||||
message="COM_USERS_PROFILE_EMAIL1_MESSAGE"
|
||||
required="true"
|
||||
size="30"
|
||||
unique="true"
|
||||
validate="email"
|
||||
/>
|
||||
|
||||
<field name="email2" type="email"
|
||||
description="COM_USERS_PROFILE_EMAIL2_DESC"
|
||||
field="email1"
|
||||
filter="string"
|
||||
label="COM_USERS_PROFILE_EMAIL2_LABEL"
|
||||
message="COM_USERS_PROFILE_EMAIL2_MESSAGE"
|
||||
required="true"
|
||||
size="30"
|
||||
validate="equals"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
85
components/com_users/models/forms/registration.xml
Normal file
85
components/com_users/models/forms/registration.xml
Normal file
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="default"
|
||||
label="COM_USERS_REGISTRATION_DEFAULT_LABEL"
|
||||
>
|
||||
|
||||
<field name="spacer" type="spacer" class="text"
|
||||
label="COM_USERS_REGISTER_REQUIRED"
|
||||
/>
|
||||
|
||||
<field name="name" type="text"
|
||||
description="COM_USERS_REGISTER_NAME_DESC"
|
||||
filter="string"
|
||||
label="COM_USERS_REGISTER_NAME_LABEL"
|
||||
required="true"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field name="username" type="text"
|
||||
class="validate-username"
|
||||
description="COM_USERS_DESIRED_USERNAME"
|
||||
filter="username"
|
||||
label="COM_USERS_REGISTER_USERNAME_LABEL"
|
||||
message="COM_USERS_REGISTER_USERNAME_MESSAGE"
|
||||
required="true"
|
||||
size="30"
|
||||
validate="username"
|
||||
/>
|
||||
|
||||
<field name="password2" type="password"
|
||||
autocomplete="off"
|
||||
class="validate-password"
|
||||
description="COM_USERS_DESIRED_PASSWORD"
|
||||
field="password1"
|
||||
filter="raw"
|
||||
label="COM_USERS_PROFILE_PASSWORD1_LABEL"
|
||||
message="COM_USERS_PROFILE_PASSWORD1_MESSAGE"
|
||||
size="30"
|
||||
validate="equals"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field name="password1" type="password"
|
||||
autocomplete="off"
|
||||
class="validate-password"
|
||||
description="COM_USERS_PROFILE_PASSWORD2_DESC"
|
||||
filter="raw"
|
||||
label="COM_USERS_PROFILE_PASSWORD2_LABEL"
|
||||
size="30"
|
||||
validate="password"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field name="email1" type="email"
|
||||
description="COM_USERS_REGISTER_EMAIL1_DESC"
|
||||
field="id"
|
||||
filter="string"
|
||||
label="COM_USERS_REGISTER_EMAIL1_LABEL"
|
||||
message="COM_USERS_REGISTER_EMAIL1_MESSAGE"
|
||||
required="true"
|
||||
size="30"
|
||||
unique="true"
|
||||
validate="email"
|
||||
/>
|
||||
|
||||
<field name="email2" type="email"
|
||||
description="COM_USERS_REGISTER_EMAIL2_DESC"
|
||||
field="email1"
|
||||
filter="string"
|
||||
label="COM_USERS_REGISTER_EMAIL2_LABEL"
|
||||
message="COM_USERS_REGISTER_EMAIL2_MESSAGE"
|
||||
required="true"
|
||||
size="30"
|
||||
validate="equals"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="captcha"
|
||||
type="captcha"
|
||||
label="COM_USERS_CAPTCHA_LABEL"
|
||||
description="COM_USERS_CAPTCHA_DESC"
|
||||
validate="captcha"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
19
components/com_users/models/forms/remind.xml
Normal file
19
components/com_users/models/forms/remind.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="default" label="COM_USERS_REMIND_DEFAULT_LABEL">
|
||||
<field name="email" type="email"
|
||||
description="COM_USERS_FIELD_REMIND_EMAIL_DESC"
|
||||
label="COM_USERS_FIELD_REMIND_EMAIL_LABEL"
|
||||
required="true"
|
||||
size="30"
|
||||
validate="email"
|
||||
/>
|
||||
<field
|
||||
name="captcha"
|
||||
type="captcha"
|
||||
label="COM_USERS_CAPTCHA_LABEL"
|
||||
description="COM_USERS_CAPTCHA_DESC"
|
||||
validate="captcha"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
27
components/com_users/models/forms/reset_complete.xml
Normal file
27
components/com_users/models/forms/reset_complete.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="default" label="COM_USERS_RESET_COMPLETE_LABEL">
|
||||
|
||||
<field name="password1" type="password"
|
||||
autocomplete="off"
|
||||
class="validate-password"
|
||||
description="COM_USERS_FIELD_RESET_PASSWORD1_DESC"
|
||||
field="password2"
|
||||
filter="raw"
|
||||
label="COM_USERS_FIELD_RESET_PASSWORD1_LABEL"
|
||||
message="COM_USERS_FIELD_RESET_PASSWORD1_MESSAGE"
|
||||
required="true"
|
||||
size="30"
|
||||
validate="equals"
|
||||
/>
|
||||
<field name="password2" type="password"
|
||||
autocomplete="off"
|
||||
class="validate-password"
|
||||
description="COM_USERS_FIELD_RESET_PASSWORD2_DESC"
|
||||
filter="raw"
|
||||
label="COM_USERS_FIELD_RESET_PASSWORD2_LABEL"
|
||||
required="true"
|
||||
size="30"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
18
components/com_users/models/forms/reset_confirm.xml
Normal file
18
components/com_users/models/forms/reset_confirm.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="default" label="COM_USERS_RESET_CONFIRM_LABEL">
|
||||
<field name="username" type="text"
|
||||
description="COM_USERS_FIELD_RESET_CONFIRM_USERNAME_DESC"
|
||||
filter="username"
|
||||
label="COM_USERS_FIELD_RESET_CONFIRM_USERNAME_LABEL"
|
||||
required="true"
|
||||
size="30"/>
|
||||
|
||||
<field name="token" type="text"
|
||||
description="COM_USERS_FIELD_RESET_CONFIRM_TOKEN_DESC"
|
||||
filter="alnum"
|
||||
label="COM_USERS_FIELD_RESET_CONFIRM_TOKEN_LABEL"
|
||||
required="true"
|
||||
size="32"/>
|
||||
</fieldset>
|
||||
</form>
|
20
components/com_users/models/forms/reset_request.xml
Normal file
20
components/com_users/models/forms/reset_request.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="default" label="COM_USERS_RESET_REQUEST_LABEL">
|
||||
<field name="email" type="text"
|
||||
class="validate-username"
|
||||
description="COM_USERS_FIELD_PASSWORD_RESET_DESC"
|
||||
filter="email" label="COM_USERS_FIELD_PASSWORD_RESET_LABEL"
|
||||
required="true"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="captcha"
|
||||
type="captcha"
|
||||
label="COM_USERS_CAPTCHA_LABEL"
|
||||
description="COM_USERS_CAPTCHA_DESC"
|
||||
validate="captcha"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
14
components/com_users/models/forms/sitelang.xml
Normal file
14
components/com_users/models/forms/sitelang.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fields name="params">
|
||||
<fieldset name="params" label="COM_USERS_SETTINGS_FIELDSET_LABEL">
|
||||
<field name="language" type="language"
|
||||
client="site"
|
||||
description="COM_USERS_USER_FIELD_FRONTEND_LANGUAGE_DESC"
|
||||
label="COM_USERS_USER_FIELD_FRONTEND_LANGUAGE_LABEL"
|
||||
required="true"
|
||||
filter="cmd"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
1
components/com_users/models/index.html
Normal file
1
components/com_users/models/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
110
components/com_users/models/login.php
Normal file
110
components/com_users/models/login.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Rest model class for Users.
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelLogin extends JModelForm
|
||||
{
|
||||
/**
|
||||
* Method to get the login form.
|
||||
*
|
||||
* The base form is loaded from XML and then an event is fired
|
||||
* for users plugins to extend the form with extra fields.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.login', 'login', array('load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return array The default data is an empty array.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered login form data.
|
||||
$app = JFactory::getApplication();
|
||||
$data = $app->getUserState('users.login.form.data', array());
|
||||
|
||||
// check for return URL from the request first
|
||||
if ($return = JRequest::getVar('return', '', 'method', 'base64'))
|
||||
{
|
||||
$data['return'] = base64_decode($return);
|
||||
if (!JUri::isInternal($data['return']))
|
||||
{
|
||||
$data['return'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Set the return URL if empty.
|
||||
if (!isset($data['return']) || empty($data['return']))
|
||||
{
|
||||
$data['return'] = 'index.php?option=com_users&view=profile';
|
||||
}
|
||||
$app->setUserState('users.login.form.data', $data);
|
||||
|
||||
$this->preprocessData('com_users.login', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
// Get the application object.
|
||||
$params = JFactory::getApplication()->getParams('com_users');
|
||||
|
||||
// Load the parameters.
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override JModelAdmin::preprocessForm to ensure the correct plugin group is loaded.
|
||||
*
|
||||
* @param JForm $form A JForm object.
|
||||
* @param mixed $data The data expected for the form.
|
||||
* @param string $group The name of the plugin group to import (defaults to "content").
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
* @throws Exception if there is an error in the form event.
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $group = 'user')
|
||||
{
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
}
|
286
components/com_users/models/profile.php
Normal file
286
components/com_users/models/profile.php
Normal file
@ -0,0 +1,286 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Profile model class for Users.
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelProfile extends JModelForm
|
||||
{
|
||||
/**
|
||||
* @var object The user profile data.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Method to check in a user.
|
||||
*
|
||||
* @param integer The id of the row to check out.
|
||||
* @return boolean True on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function checkin($userId = null)
|
||||
{
|
||||
// Get the user id.
|
||||
$userId = (!empty($userId)) ? $userId : (int) $this->getState('user.id');
|
||||
|
||||
if ($userId)
|
||||
{
|
||||
// Initialise the table with JUser.
|
||||
$table = JTable::getInstance('User');
|
||||
|
||||
// Attempt to check the row in.
|
||||
if (!$table->checkin($userId))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check out a user for editing.
|
||||
*
|
||||
* @param integer The id of the row to check out.
|
||||
* @return boolean True on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function checkout($userId = null)
|
||||
{
|
||||
// Get the user id.
|
||||
$userId = (!empty($userId)) ? $userId : (int) $this->getState('user.id');
|
||||
|
||||
if ($userId)
|
||||
{
|
||||
// Initialise the table with JUser.
|
||||
$table = JTable::getInstance('User');
|
||||
|
||||
// Get the current user object.
|
||||
$user = JFactory::getUser();
|
||||
|
||||
// Attempt to check the row out.
|
||||
if (!$table->checkout($user->get('id'), $userId))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the profile form data.
|
||||
*
|
||||
* The base form data is loaded and then an event is fired
|
||||
* for users plugins to extend the data.
|
||||
*
|
||||
* @return mixed Data object on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
if ($this->data === null) {
|
||||
|
||||
$userId = $this->getState('user.id');
|
||||
|
||||
// Initialise the table with JUser.
|
||||
$this->data = new JUser($userId);
|
||||
|
||||
// Set the base user data.
|
||||
$this->data->email1 = $this->data->get('email');
|
||||
$this->data->email2 = $this->data->get('email');
|
||||
|
||||
// Override the base user data with any data in the session.
|
||||
$temp = (array) JFactory::getApplication()->getUserState('com_users.edit.profile.data', array());
|
||||
foreach ($temp as $k => $v)
|
||||
{
|
||||
$this->data->$k = $v;
|
||||
}
|
||||
|
||||
// Unset the passwords.
|
||||
unset($this->data->password1);
|
||||
unset($this->data->password2);
|
||||
|
||||
$registry = new JRegistry($this->data->params);
|
||||
$this->data->params = $registry->toArray();
|
||||
|
||||
// Get the dispatcher and load the users plugins.
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Trigger the data preparation event.
|
||||
$results = $dispatcher->trigger('onContentPrepareData', array('com_users.profile', $this->data));
|
||||
|
||||
// Check for errors encountered while preparing the data.
|
||||
if (count($results) && in_array(false, $results, true))
|
||||
{
|
||||
$this->setError($dispatcher->getError());
|
||||
$this->data = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the profile form.
|
||||
*
|
||||
* The base form is loaded from XML and then an event is fired
|
||||
* for users plugins to extend the form with extra fields.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.profile', 'profile', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!JComponentHelper::getParams('com_users')->get('change_login_name'))
|
||||
{
|
||||
$form->setFieldAttribute('username', 'class', '');
|
||||
$form->setFieldAttribute('username', 'filter', '');
|
||||
$form->setFieldAttribute('username', 'description', 'COM_USERS_PROFILE_NOCHANGE_USERNAME_DESC');
|
||||
$form->setFieldAttribute('username', 'validate', '');
|
||||
$form->setFieldAttribute('username', 'message', '');
|
||||
$form->setFieldAttribute('username', 'readonly', 'true');
|
||||
$form->setFieldAttribute('username', 'required', 'false');
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
$data = $this->getData();
|
||||
|
||||
$this->preprocessData('com_users.profile', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override preprocessForm to load the user plugin group instead of content.
|
||||
*
|
||||
* @param object A form object.
|
||||
* @param mixed The data expected for the form.
|
||||
* @throws Exception if there is an error in the form event.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $group = 'user')
|
||||
{
|
||||
if (JComponentHelper::getParams('com_users')->get('frontend_userparams'))
|
||||
{
|
||||
$form->loadFile('frontend', false);
|
||||
if (JFactory::getUser()->authorise('core.login.admin'))
|
||||
{
|
||||
$form->loadFile('frontend_admin', false);
|
||||
}
|
||||
}
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
// Get the application object.
|
||||
$params = JFactory::getApplication()->getParams('com_users');
|
||||
|
||||
// Get the user id.
|
||||
$userId = JFactory::getApplication()->getUserState('com_users.edit.profile.id');
|
||||
$userId = !empty($userId) ? $userId : (int) JFactory::getUser()->get('id');
|
||||
|
||||
// Set the user id.
|
||||
$this->setState('user.id', $userId);
|
||||
|
||||
// Load the parameters.
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array The form data.
|
||||
* @return mixed The user id on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$userId = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('user.id');
|
||||
|
||||
$user = new JUser($userId);
|
||||
|
||||
// Prepare the data for the user object.
|
||||
$data['email'] = JStringPunycode::emailToPunycode($data['email1']);
|
||||
$data['password'] = $data['password1'];
|
||||
|
||||
// Unset the username if it should not be overwritten
|
||||
if (!JComponentHelper::getParams('com_users')->get('change_login_name'))
|
||||
{
|
||||
unset($data['username']);
|
||||
}
|
||||
|
||||
// Unset the block so it does not get overwritten
|
||||
unset($data['block']);
|
||||
|
||||
// Unset the sendEmail so it does not get overwritten
|
||||
unset($data['sendEmail']);
|
||||
|
||||
// Bind the data.
|
||||
if (!$user->bind($data))
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the users plugin group.
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Null the user groups so they don't get overwritten
|
||||
$user->groups = null;
|
||||
|
||||
// Store the data.
|
||||
if (!$user->save())
|
||||
{
|
||||
$this->setError($user->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
$user->tags = new JHelperTags;
|
||||
$user->tags->getTagIds($user->id, 'com_users.user');
|
||||
|
||||
return $user->id;
|
||||
}
|
||||
}
|
616
components/com_users/models/registration.php
Normal file
616
components/com_users/models/registration.php
Normal file
@ -0,0 +1,616 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Registration model class for Users.
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelRegistration extends JModelForm
|
||||
{
|
||||
/**
|
||||
* @var object The user registration data.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Method to activate a user account.
|
||||
*
|
||||
* @param string $token The activation token.
|
||||
*
|
||||
* @return mixed False on failure, user object on success.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function activate($token)
|
||||
{
|
||||
$config = JFactory::getConfig();
|
||||
$userParams = JComponentHelper::getParams('com_users');
|
||||
$db = $this->getDbo();
|
||||
|
||||
// Get the user id based on the token.
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__users'))
|
||||
->where($db->quoteName('activation') . ' = ' . $db->quote($token))
|
||||
->where($db->quoteName('block') . ' = ' . 1)
|
||||
->where($db->quoteName('lastvisitDate') . ' = ' . $db->quote($db->getNullDate()));
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$userId = (int) $db->loadResult();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for a valid user id.
|
||||
if (!$userId)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_ACTIVATION_TOKEN_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the users plugin group.
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Activate the user.
|
||||
$user = JFactory::getUser($userId);
|
||||
|
||||
// Admin activation is on and user is verifying their email
|
||||
if (($userParams->get('useractivation') == 2) && !$user->getParam('activate', 0))
|
||||
{
|
||||
$uri = JUri::getInstance();
|
||||
|
||||
// Compile the admin notification mail values.
|
||||
$data = $user->getProperties();
|
||||
$data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
|
||||
$user->set('activation', $data['activation']);
|
||||
$data['siteurl'] = JUri::base();
|
||||
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
|
||||
$data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
|
||||
$data['fromname'] = $config->get('fromname');
|
||||
$data['mailfrom'] = $config->get('mailfrom');
|
||||
$data['sitename'] = $config->get('sitename');
|
||||
$user->setParam('activate', 1);
|
||||
$emailSubject = JText::sprintf(
|
||||
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT',
|
||||
$data['name'],
|
||||
$data['sitename']
|
||||
);
|
||||
|
||||
$emailBody = JText::sprintf(
|
||||
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY',
|
||||
$data['sitename'],
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['username'],
|
||||
$data['activate']
|
||||
);
|
||||
|
||||
// get all admin users
|
||||
$query->clear()
|
||||
->select($db->quoteName(array('name', 'email', 'sendEmail', 'id')))
|
||||
->from($db->quoteName('#__users'))
|
||||
->where($db->quoteName('sendEmail') . ' = ' . 1);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$rows = $db->loadObjectList();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send mail to all users with users creating permissions and receiving system emails
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$usercreator = JFactory::getUser($row->id);
|
||||
|
||||
if ($usercreator->authorise('core.create', 'com_users'))
|
||||
{
|
||||
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
|
||||
|
||||
// Check for an error.
|
||||
if ($return !== true)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Admin activation is on and admin is activating the account
|
||||
elseif (($userParams->get('useractivation') == 2) && $user->getParam('activate', 0))
|
||||
{
|
||||
$user->set('activation', '');
|
||||
$user->set('block', '0');
|
||||
|
||||
// Compile the user activated notification mail values.
|
||||
$data = $user->getProperties();
|
||||
$user->setParam('activate', 0);
|
||||
$data['fromname'] = $config->get('fromname');
|
||||
$data['mailfrom'] = $config->get('mailfrom');
|
||||
$data['sitename'] = $config->get('sitename');
|
||||
$data['siteurl'] = JUri::base();
|
||||
$emailSubject = JText::sprintf(
|
||||
'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_SUBJECT',
|
||||
$data['name'],
|
||||
$data['sitename']
|
||||
);
|
||||
|
||||
$emailBody = JText::sprintf(
|
||||
'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_BODY',
|
||||
$data['name'],
|
||||
$data['siteurl'],
|
||||
$data['username']
|
||||
);
|
||||
|
||||
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
|
||||
|
||||
// Check for an error.
|
||||
if ($return !== true)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$user->set('activation', '');
|
||||
$user->set('block', '0');
|
||||
}
|
||||
|
||||
// Store the user object.
|
||||
if (!$user->save())
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED', $user->getError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the registration form data.
|
||||
*
|
||||
* The base form data is loaded and then an event is fired
|
||||
* for users plugins to extend the data.
|
||||
*
|
||||
* @return mixed Data object on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
if ($this->data === null)
|
||||
{
|
||||
$this->data = new stdClass;
|
||||
$app = JFactory::getApplication();
|
||||
$params = JComponentHelper::getParams('com_users');
|
||||
|
||||
// Override the base user data with any data in the session.
|
||||
$temp = (array) $app->getUserState('com_users.registration.data', array());
|
||||
foreach ($temp as $k => $v)
|
||||
{
|
||||
$this->data->$k = $v;
|
||||
}
|
||||
|
||||
// Get the groups the user should be added to after registration.
|
||||
$this->data->groups = array();
|
||||
|
||||
// Get the default new user group, Registered if not specified.
|
||||
$system = $params->get('new_usertype', 2);
|
||||
|
||||
$this->data->groups[] = $system;
|
||||
|
||||
// Unset the passwords.
|
||||
unset($this->data->password1);
|
||||
unset($this->data->password2);
|
||||
|
||||
// Get the dispatcher and load the users plugins.
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Trigger the data preparation event.
|
||||
$results = $dispatcher->trigger('onContentPrepareData', array('com_users.registration', $this->data));
|
||||
|
||||
// Check for errors encountered while preparing the data.
|
||||
if (count($results) && in_array(false, $results, true))
|
||||
{
|
||||
$this->setError($dispatcher->getError());
|
||||
$this->data = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the registration form.
|
||||
*
|
||||
* The base form is loaded from XML and then an event is fired
|
||||
* for users plugins to extend the form with extra fields.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.registration', 'registration', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
$data = $this->getData();
|
||||
|
||||
$this->preprocessData('com_users.registration', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override preprocessForm to load the user plugin group instead of content.
|
||||
*
|
||||
* @param JForm $form A JForm object.
|
||||
* @param mixed $data The data expected for the form.
|
||||
* @param string $group The name of the plugin group to import (defaults to "content").
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
* @throws Exception if there is an error in the form event.
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $group = 'user')
|
||||
{
|
||||
$userParams = JComponentHelper::getParams('com_users');
|
||||
|
||||
//Add the choice for site language at registration time
|
||||
if ($userParams->get('site_language') == 1 && $userParams->get('frontend_userparams') == 1)
|
||||
{
|
||||
$form->loadFile('sitelang', false);
|
||||
}
|
||||
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
// Get the application object.
|
||||
$app = JFactory::getApplication();
|
||||
$params = $app->getParams('com_users');
|
||||
|
||||
// Load the parameters.
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array $temp The form data.
|
||||
*
|
||||
* @return mixed The user id on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function register($temp)
|
||||
{
|
||||
$params = JComponentHelper::getParams('com_users');
|
||||
|
||||
// Initialise the table with JUser.
|
||||
$user = new JUser;
|
||||
$data = (array) $this->getData();
|
||||
|
||||
// Merge in the registration data.
|
||||
foreach ($temp as $k => $v)
|
||||
{
|
||||
$data[$k] = $v;
|
||||
}
|
||||
|
||||
// Prepare the data for the user object.
|
||||
$data['email'] = JStringPunycode::emailToPunycode($data['email1']);
|
||||
$data['password'] = $data['password1'];
|
||||
$useractivation = $params->get('useractivation');
|
||||
$sendpassword = $params->get('sendpassword', 1);
|
||||
|
||||
// Check if the user needs to activate their account.
|
||||
if (($useractivation == 1) || ($useractivation == 2))
|
||||
{
|
||||
$data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
|
||||
$data['block'] = 1;
|
||||
}
|
||||
|
||||
// Bind the data.
|
||||
if (!$user->bind($data))
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the users plugin group.
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Store the data.
|
||||
if (!$user->save())
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
$config = JFactory::getConfig();
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Compile the notification mail values.
|
||||
$data = $user->getProperties();
|
||||
$data['fromname'] = $config->get('fromname');
|
||||
$data['mailfrom'] = $config->get('mailfrom');
|
||||
$data['sitename'] = $config->get('sitename');
|
||||
$data['siteurl'] = JUri::root();
|
||||
|
||||
// Handle account activation/confirmation emails.
|
||||
if ($useractivation == 2)
|
||||
{
|
||||
// Set the link to confirm the user email.
|
||||
$uri = JUri::getInstance();
|
||||
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
|
||||
$data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
|
||||
|
||||
$emailSubject = JText::sprintf(
|
||||
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
|
||||
$data['name'],
|
||||
$data['sitename']
|
||||
);
|
||||
|
||||
if ($sendpassword)
|
||||
{
|
||||
$emailBody = JText::sprintf(
|
||||
'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY',
|
||||
$data['name'],
|
||||
$data['sitename'],
|
||||
$data['activate'],
|
||||
$data['siteurl'],
|
||||
$data['username'],
|
||||
$data['password_clear']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$emailBody = JText::sprintf(
|
||||
'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW',
|
||||
$data['name'],
|
||||
$data['sitename'],
|
||||
$data['activate'],
|
||||
$data['siteurl'],
|
||||
$data['username']
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif ($useractivation == 1)
|
||||
{
|
||||
// Set the link to activate the user account.
|
||||
$uri = JUri::getInstance();
|
||||
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
|
||||
$data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
|
||||
|
||||
$emailSubject = JText::sprintf(
|
||||
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
|
||||
$data['name'],
|
||||
$data['sitename']
|
||||
);
|
||||
|
||||
if ($sendpassword)
|
||||
{
|
||||
$emailBody = JText::sprintf(
|
||||
'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY',
|
||||
$data['name'],
|
||||
$data['sitename'],
|
||||
$data['activate'],
|
||||
$data['siteurl'],
|
||||
$data['username'],
|
||||
$data['password_clear']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$emailBody = JText::sprintf(
|
||||
'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW',
|
||||
$data['name'],
|
||||
$data['sitename'],
|
||||
$data['activate'],
|
||||
$data['siteurl'],
|
||||
$data['username']
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$emailSubject = JText::sprintf(
|
||||
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
|
||||
$data['name'],
|
||||
$data['sitename']
|
||||
);
|
||||
|
||||
if ($sendpassword)
|
||||
{
|
||||
$emailBody = JText::sprintf(
|
||||
'COM_USERS_EMAIL_REGISTERED_BODY',
|
||||
$data['name'],
|
||||
$data['sitename'],
|
||||
$data['siteurl'],
|
||||
$data['username'],
|
||||
$data['password_clear']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$emailBody = JText::sprintf(
|
||||
'COM_USERS_EMAIL_REGISTERED_BODY_NOPW',
|
||||
$data['name'],
|
||||
$data['sitename'],
|
||||
$data['siteurl']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Send the registration email.
|
||||
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
|
||||
|
||||
// Send Notification mail to administrators
|
||||
if (($params->get('useractivation') < 2) && ($params->get('mail_to_admin') == 1))
|
||||
{
|
||||
$emailSubject = JText::sprintf(
|
||||
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
|
||||
$data['name'],
|
||||
$data['sitename']
|
||||
);
|
||||
|
||||
$emailBodyAdmin = JText::sprintf(
|
||||
'COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY',
|
||||
$data['name'],
|
||||
$data['username'],
|
||||
$data['siteurl']
|
||||
);
|
||||
|
||||
// Get all admin users
|
||||
$query->clear()
|
||||
->select($db->quoteName(array('name', 'email', 'sendEmail')))
|
||||
->from($db->quoteName('#__users'))
|
||||
->where($db->quoteName('sendEmail') . ' = ' . 1);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$rows = $db->loadObjectList();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send mail to all superadministrators id
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBodyAdmin);
|
||||
|
||||
// Check for an error.
|
||||
if ($return !== true)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for an error.
|
||||
if ($return !== true)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'));
|
||||
|
||||
// Send a system message to administrators receiving system mails
|
||||
$db = JFactory::getDbo();
|
||||
$query->clear()
|
||||
->select($db->quoteName(array('name', 'email', 'sendEmail', 'id')))
|
||||
->from($db->quoteName('#__users'))
|
||||
->where($db->quoteName('block') . ' = ' . (int) 0)
|
||||
->where($db->quoteName('sendEmail') . ' = ' . (int) 1);
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$sendEmail = $db->loadColumn();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($sendEmail) > 0)
|
||||
{
|
||||
$jdate = new JDate;
|
||||
|
||||
// Build the query to add the messages
|
||||
foreach ($sendEmail as $userid)
|
||||
{
|
||||
$values = array($db->quote($userid), $db->quote($userid), $db->quote($jdate->toSql()), $db->quote(JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')), $db->quote(JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username'])));
|
||||
$query->clear()
|
||||
->insert($db->quoteName('#__messages'))
|
||||
->columns($db->quoteName(array('user_id_from', 'user_id_to', 'date_time', 'subject', 'message')))
|
||||
->values(implode(',', $values));
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$db->execute();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($useractivation == 1)
|
||||
{
|
||||
return "useractivate";
|
||||
}
|
||||
elseif ($useractivation == 2)
|
||||
{
|
||||
return "adminactivate";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $user->id;
|
||||
}
|
||||
}
|
||||
}
|
179
components/com_users/models/remind.php
Normal file
179
components/com_users/models/remind.php
Normal file
@ -0,0 +1,179 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Remind model class for Users.
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
* @since 1.5
|
||||
*/
|
||||
class UsersModelRemind extends JModelForm
|
||||
{
|
||||
/**
|
||||
* Method to get the username remind request form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.remind', 'remind', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override preprocessForm to load the user plugin group instead of content.
|
||||
*
|
||||
* @param object A form object.
|
||||
* @param mixed The data expected for the form.
|
||||
* @throws Exception if there is an error in the form event.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $group = 'user')
|
||||
{
|
||||
parent::preprocessForm($form, $data, 'user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
// Get the application object.
|
||||
$app = JFactory::getApplication();
|
||||
$params = $app->getParams('com_users');
|
||||
|
||||
// Load the parameters.
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.6
|
||||
*/
|
||||
public function processRemindRequest($data)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->getForm();
|
||||
$data['email'] = JStringPunycode::emailToPunycode($data['email']);
|
||||
|
||||
// Check for an error.
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the data.
|
||||
$data = $this->validate($form, $data);
|
||||
|
||||
// Check for an error.
|
||||
if ($data instanceof Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the validation results.
|
||||
if ($data === false)
|
||||
{
|
||||
// Get the validation messages from the form.
|
||||
foreach ($form->getErrors() as $formError)
|
||||
{
|
||||
$this->setError($formError->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the user id for the given email address.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('*')
|
||||
->from($db->quoteName('#__users'))
|
||||
->where($db->quoteName('email') . ' = ' . $db->quote($data['email']));
|
||||
|
||||
// Get the user id.
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$user = $db->loadObject();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for a user.
|
||||
if (empty($user))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the user isn't blocked.
|
||||
if ($user->block)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_BLOCKED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$config = JFactory::getConfig();
|
||||
|
||||
// Assemble the login link.
|
||||
$itemid = UsersHelperRoute::getLoginRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
|
||||
$link = 'index.php?option=com_users&view=login' . $itemid;
|
||||
$mode = $config->get('force_ssl', 0) == 2 ? 1 : -1;
|
||||
|
||||
// Put together the email template data.
|
||||
$data = JArrayHelper::fromObject($user);
|
||||
$data['fromname'] = $config->get('fromname');
|
||||
$data['mailfrom'] = $config->get('mailfrom');
|
||||
$data['sitename'] = $config->get('sitename');
|
||||
$data['link_text'] = JRoute::_($link, false, $mode);
|
||||
$data['link_html'] = JRoute::_($link, true, $mode);
|
||||
|
||||
$subject = JText::sprintf(
|
||||
'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT',
|
||||
$data['sitename']
|
||||
);
|
||||
$body = JText::sprintf(
|
||||
'COM_USERS_EMAIL_USERNAME_REMINDER_BODY',
|
||||
$data['sitename'],
|
||||
$data['username'],
|
||||
$data['link_text']
|
||||
);
|
||||
|
||||
// Send the password reset request email.
|
||||
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body);
|
||||
|
||||
// Check for an error.
|
||||
if ($return !== true)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_MAIL_FAILED'), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
475
components/com_users/models/reset.php
Normal file
475
components/com_users/models/reset.php
Normal file
@ -0,0 +1,475 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Rest model class for Users.
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_users
|
||||
* @since 1.5
|
||||
*/
|
||||
class UsersModelReset extends JModelForm
|
||||
{
|
||||
/**
|
||||
* Method to get the password reset request form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.reset_request', 'reset_request', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the password reset complete form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getResetCompleteForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.reset_complete', 'reset_complete', $options = array('control' => 'jform'));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the password reset confirm form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getResetConfirmForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.reset_confirm', 'reset_confirm', $options = array('control' => 'jform'));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override preprocessForm to load the user plugin group instead of content.
|
||||
*
|
||||
* @param object A form object.
|
||||
* @param mixed The data expected for the form.
|
||||
* @throws Exception if there is an error in the form event.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $group = 'user')
|
||||
{
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
// Get the application object.
|
||||
$params = JFactory::getApplication()->getParams('com_users');
|
||||
|
||||
// Load the parameters.
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.6
|
||||
*/
|
||||
function processResetComplete($data)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->getResetCompleteForm();
|
||||
$data['email'] = JStringPunycode::emailToPunycode($data['email']);
|
||||
|
||||
// Check for an error.
|
||||
if ($form instanceof Exception)
|
||||
{
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Filter and validate the form data.
|
||||
$data = $form->filter($data);
|
||||
$return = $form->validate($data);
|
||||
|
||||
// Check for an error.
|
||||
if ($return instanceof Exception)
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
|
||||
// Check the validation results.
|
||||
if ($return === false)
|
||||
{
|
||||
// Get the validation messages from the form.
|
||||
foreach ($form->getErrors() as $formError)
|
||||
{
|
||||
$this->setError($formError->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the token and user id from the confirmation process.
|
||||
$app = JFactory::getApplication();
|
||||
$token = $app->getUserState('com_users.reset.token', null);
|
||||
$userId = $app->getUserState('com_users.reset.user', null);
|
||||
|
||||
// Check the token and user id.
|
||||
if (empty($token) || empty($userId))
|
||||
{
|
||||
return new JException(JText::_('COM_USERS_RESET_COMPLETE_TOKENS_MISSING'), 403);
|
||||
}
|
||||
|
||||
// Get the user object.
|
||||
$user = JUser::getInstance($userId);
|
||||
|
||||
// Check for a user and that the tokens match.
|
||||
if (empty($user) || $user->activation !== $token)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the user isn't blocked.
|
||||
if ($user->block)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_BLOCKED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Generate the new password hash.
|
||||
$salt = JUserHelper::genRandomPassword(32);
|
||||
$crypted = JUserHelper::getCryptedPassword($data['password1'], $salt);
|
||||
$password = $crypted . ':' . $salt;
|
||||
|
||||
// Update the user object.
|
||||
$user->password = $password;
|
||||
$user->activation = '';
|
||||
$user->password_clear = $data['password1'];
|
||||
|
||||
// Save the user to the database.
|
||||
if (!$user->save(true))
|
||||
{
|
||||
return new JException(JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500);
|
||||
}
|
||||
|
||||
// Flush the user data from the session.
|
||||
$app->setUserState('com_users.reset.token', null);
|
||||
$app->setUserState('com_users.reset.user', null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.6
|
||||
*/
|
||||
function processResetConfirm($data)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->getResetConfirmForm();
|
||||
$data['email'] = JStringPunycode::emailToPunycode($data['email']);
|
||||
|
||||
// Check for an error.
|
||||
if ($form instanceof Exception)
|
||||
{
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Filter and validate the form data.
|
||||
$data = $form->filter($data);
|
||||
$return = $form->validate($data);
|
||||
|
||||
// Check for an error.
|
||||
if ($return instanceof Exception)
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
|
||||
// Check the validation results.
|
||||
if ($return === false)
|
||||
{
|
||||
// Get the validation messages from the form.
|
||||
foreach ($form->getErrors() as $formError)
|
||||
{
|
||||
$this->setError($formError->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the user id for the given token.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('activation')
|
||||
->select('id')
|
||||
->select('block')
|
||||
->from($db->quoteName('#__users'))
|
||||
->where($db->quoteName('username') . ' = ' . $db->quote($data['username']));
|
||||
|
||||
// Get the user id.
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$user = $db->loadObject();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
return new JException(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
|
||||
}
|
||||
|
||||
// Check for a user.
|
||||
if (empty($user))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = explode(':', $user->activation);
|
||||
$crypt = $parts[0];
|
||||
if (!isset($parts[1]))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
$salt = $parts[1];
|
||||
$testcrypt = JUserHelper::getCryptedPassword($data['token'], $salt);
|
||||
|
||||
// Verify the token
|
||||
if (!($crypt == $testcrypt))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the user isn't blocked.
|
||||
if ($user->block)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_BLOCKED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Push the user data into the session.
|
||||
$app = JFactory::getApplication();
|
||||
$app->setUserState('com_users.reset.token', $crypt . ':' . $salt);
|
||||
$app->setUserState('com_users.reset.user', $user->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to start the password reset process.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function processResetRequest($data)
|
||||
{
|
||||
$config = JFactory::getConfig();
|
||||
|
||||
// Get the form.
|
||||
$form = $this->getForm();
|
||||
|
||||
$data['email'] = JStringPunycode::emailToPunycode($data['email']);
|
||||
|
||||
// Check for an error.
|
||||
if ($form instanceof Exception)
|
||||
{
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Filter and validate the form data.
|
||||
$data = $form->filter($data);
|
||||
$return = $form->validate($data);
|
||||
|
||||
// Check for an error.
|
||||
if ($return instanceof Exception)
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
|
||||
// Check the validation results.
|
||||
if ($return === false)
|
||||
{
|
||||
// Get the validation messages from the form.
|
||||
foreach ($form->getErrors() as $formError)
|
||||
{
|
||||
$this->setError($formError->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the user id for the given email address.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('id')
|
||||
->from($db->quoteName('#__users'))
|
||||
->where($db->quoteName('email') . ' = ' . $db->quote($data['email']));
|
||||
|
||||
// Get the user object.
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$userId = $db->loadResult();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for a user.
|
||||
if (empty($userId))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_INVALID_EMAIL'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the user object.
|
||||
$user = JUser::getInstance($userId);
|
||||
|
||||
// Make sure the user isn't blocked.
|
||||
if ($user->block)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USER_BLOCKED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the user isn't a Super Admin.
|
||||
if ($user->authorise('core.admin'))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_REMIND_SUPERADMIN_ERROR'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the user has not exceeded the reset limit
|
||||
if (!$this->checkResetLimit($user))
|
||||
{
|
||||
$resetLimit = (int) JFactory::getApplication()->getParams()->get('reset_time');
|
||||
$this->setError(JText::plural('COM_USERS_REMIND_LIMIT_ERROR_N_HOURS', $resetLimit));
|
||||
return false;
|
||||
}
|
||||
// Set the confirmation token.
|
||||
$token = JApplication::getHash(JUserHelper::genRandomPassword());
|
||||
$salt = JUserHelper::getSalt('crypt-md5');
|
||||
$hashedToken = md5($token . $salt) . ':' . $salt;
|
||||
|
||||
$user->activation = $hashedToken;
|
||||
|
||||
// Save the user to the database.
|
||||
if (!$user->save(true))
|
||||
{
|
||||
return new JException(JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500);
|
||||
}
|
||||
|
||||
// Assemble the password reset confirmation link.
|
||||
$mode = $config->get('force_ssl', 0) == 2 ? 1 : -1;
|
||||
$itemid = UsersHelperRoute::getLoginRoute();
|
||||
$itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
|
||||
$link = 'index.php?option=com_users&view=reset&layout=confirm' . $itemid;
|
||||
|
||||
// Put together the email template data.
|
||||
$data = $user->getProperties();
|
||||
$data['fromname'] = $config->get('fromname');
|
||||
$data['mailfrom'] = $config->get('mailfrom');
|
||||
$data['sitename'] = $config->get('sitename');
|
||||
$data['link_text'] = JRoute::_($link, false, $mode);
|
||||
$data['link_html'] = JRoute::_($link, true, $mode);
|
||||
$data['token'] = $token;
|
||||
|
||||
$subject = JText::sprintf(
|
||||
'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT',
|
||||
$data['sitename']
|
||||
);
|
||||
|
||||
$body = JText::sprintf(
|
||||
'COM_USERS_EMAIL_PASSWORD_RESET_BODY',
|
||||
$data['sitename'],
|
||||
$data['token'],
|
||||
$data['link_text']
|
||||
);
|
||||
|
||||
// Send the password reset request email.
|
||||
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body);
|
||||
// Check for an error.
|
||||
if ($return !== true)
|
||||
{
|
||||
return new JException(JText::_('COM_USERS_MAIL_FAILED'), 500);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if user reset limit has been exceeded within the allowed time period.
|
||||
*
|
||||
* @param JUser the user doing the password reset
|
||||
*
|
||||
* @return boolean true if user can do the reset, false if limit exceeded
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function checkResetLimit($user)
|
||||
{
|
||||
$params = JFactory::getApplication()->getParams();
|
||||
$maxCount = (int) $params->get('reset_count');
|
||||
$resetHours = (int) $params->get('reset_time');
|
||||
$result = true;
|
||||
|
||||
$lastResetTime = strtotime($user->lastResetTime) ? strtotime($user->lastResetTime) : 0;
|
||||
$hoursSinceLastReset = (strtotime(JFactory::getDate()->toSql()) - $lastResetTime) / 3600;
|
||||
|
||||
// If it's been long enough, start a new reset count
|
||||
if ($hoursSinceLastReset > $resetHours)
|
||||
{
|
||||
$user->lastResetTime = JFactory::getDate()->toSql();
|
||||
$user->resetCount = 1;
|
||||
}
|
||||
|
||||
// If we are under the max count, just increment the counter
|
||||
elseif ($user->resetCount < $maxCount)
|
||||
{
|
||||
$user->resetCount;
|
||||
}
|
||||
|
||||
// At this point, we know we have exceeded the maximum resets for the time period
|
||||
else
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user