Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6d2e8ec
add the js to the build
carlitorweb Jan 15, 2023
4a90395
activate the user and send a notification
carlitorweb Jan 16, 2023
9818951
reviewers changes
carlitorweb Jan 16, 2023
6a9d9a3
Reviewers changes
carlitorweb Jan 16, 2023
25b54d0
Update administrator/components/com_users/src/Controller/UserControll…
carlitorweb Jan 16, 2023
8bc6db7
Update administrator/components/com_users/src/Controller/UserControll…
carlitorweb Jan 16, 2023
fbde984
Update administrator/components/com_users/src/Controller/UserControll…
carlitorweb Jan 16, 2023
3b4e6fc
Merge branch '4.3-dev' into activate_send_email
carlitorweb Jan 16, 2023
39b8807
fix phpcs
carlitorweb Jan 16, 2023
095a504
js lint fixes
carlitorweb Jan 16, 2023
5da1653
reviewers changes
carlitorweb Jan 16, 2023
5c5c018
success message + reviewers changes + lenguages strings
carlitorweb Jan 18, 2023
0b3ea90
dont allow the button creating a user + reviewers changes
carlitorweb Jan 18, 2023
8edcee8
Update administrator/components/com_users/src/Controller/UserControll…
carlitorweb Jan 18, 2023
7ee0c86
Update administrator/language/en-GB/com_users.ini
obuisard Jan 20, 2023
c50472d
wrong check if user is actived
carlitorweb Jan 20, 2023
c4cab6c
Merge branch '4.3-dev' into activate_send_email
carlitorweb Jan 20, 2023
31b6734
Merge branch '4.3-dev' into activate_send_email
carlitorweb Jan 22, 2023
85fb799
Merge branch '4.3-dev' into activate_send_email
carlitorweb Jan 26, 2023
2adb5e0
Merge branch '4.3-dev' into activate_send_email
QuyTon Feb 4, 2023
d4375a8
Update administrator/components/com_users/src/View/User/HtmlView.php
QuyTon Feb 4, 2023
6b4ee8a
Merge branch '4.3-dev' into activate_send_email
QuyTon Feb 21, 2023
ae6303d
Merge branch '4.3-dev' into activate_send_email
carlitorweb Mar 11, 2023
f6a26c3
Merge branch '4.4-dev' into activate_send_email
carlitorweb Mar 11, 2023
3edd0e6
Merge branch '4.4-dev' into activate_send_email
MacJoom Mar 22, 2023
6f8fe41
Merge branch '5.1-dev' into activate_send_email
Hackwar Mar 29, 2024
f5cf34a
Remove unused import
QuyTon Apr 3, 2024
f316e46
Merge branch '5.2-dev' into activate_send_email
richard67 May 4, 2024
b13a47a
use the administrator default language for Mail template
carlitorweb May 5, 2024
c375030
use the site default language for Mail template
carlitorweb May 5, 2024
8e0f66a
Merge branch '5.2-dev' into activate_send_email
carlitorweb May 5, 2024
72c936f
Update administrator/components/com_users/src/Controller/UserControll…
carlitorweb Aug 16, 2024
41c9c84
Update administrator/components/com_users/src/Controller/UserControll…
carlitorweb Aug 16, 2024
41bc2fd
Merge branch '5.2-dev' into activate_send_email
carlitorweb Aug 18, 2024
74f21d6
Update joomla.asset.json
carlitorweb Aug 18, 2024
b7adf0a
Merge branch '5.3-dev' into activate_send_email
richard67 Sep 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
namespace Joomla\Component\Users\Administrator\Controller;

use Joomla\CMS\Access\Access;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

Expand Down Expand Up @@ -160,4 +162,34 @@ public function batch($model = null)
protected function postSaveHook(BaseDatabaseModel $model, $validData = array())
{
}

/**
* Get the XHR request for active a user
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function active(): void
{
// Get the ID of the user sended trought media/com_users/js/active-user-send-mail
$userId = $this->input->getString('userid', '');

// Prepare the default response
$responseError = false;
$responseData = [$userId];
$responseMessage = null;

// Set the model
$model = $this->getModel('User', 'Administrator', []);

// Active the user and send the email
$responseError = $model->activate($userId);

if (!$responseError) {
$responseMessage = $model->getError();
}

echo new JsonResponse($responseData, $responseMessage, $responseError);
}
}
106 changes: 76 additions & 30 deletions administrator/components/com_users/src/Model/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ protected function preprocessForm(Form $form, $data, $group = 'user')
*/
public function save($data)
{
$pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('user.id');
$user = User::getInstance($pk);
$pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('user.id');
$user = User::getInstance($pk);

$my = $this->getCurrentUser();
$my = $this->getCurrentUser();
$iAmSuperAdmin = $my->authorise('core.admin');

// User cannot modify own user groups
Expand Down Expand Up @@ -252,7 +252,7 @@ public function save($data)
if ($iAmSuperAdmin && $my->get('id') == $pk) {
// Check that at least one of our new groups is Super Admin
$stillSuperAdmin = false;
$myNewGroups = $data['groups'];
$myNewGroups = $data['groups'];

foreach ($myNewGroups as $group) {
$stillSuperAdmin = $stillSuperAdmin ?: Access::checkGroup($group, 'core.admin');
Expand Down Expand Up @@ -301,9 +301,9 @@ public function save($data)
*/
public function delete(&$pks)
{
$user = $this->getCurrentUser();
$table = $this->getTable();
$pks = (array) $pks;
$user = $this->getCurrentUser();
$table = $this->getTable();
$pks = (array) $pks;

// Check if I am a Super Admin
$iAmSuperAdmin = $user->authorise('core.admin');
Expand Down Expand Up @@ -368,8 +368,8 @@ public function delete(&$pks)
*/
public function block(&$pks, $value = 1)
{
$app = Factory::getApplication();
$user = $this->getCurrentUser();
$app = Factory::getApplication();
$user = $this->getCurrentUser();

// Check if I am a Super Admin
$iAmSuperAdmin = $user->authorise('core.admin');
Expand Down Expand Up @@ -467,31 +467,74 @@ public function block(&$pks, $value = 1)
*
* @return boolean True on success.
*
* @since 1.6
* @since __DEPLOY_VERSION__
* @throws \Exception
*/
public function activate(&$pks)
{
$user = $this->getCurrentUser();
$app = Factory::getApplication();
$user = $app->getIdentity();

// Check if I am a Super Admin
// Check if I am a super admin
$iAmSuperAdmin = $user->authorise('core.admin');

// Load user table
$table = $this->getTable();
$pks = (array) $pks;

// Compile the user activated notification mail values.
$sendMailTo = function ($userMail) use ($app)
{
$mailData = [];
$mailData['fromname'] = $app->get('fromname');
$mailData['mailfrom'] = $app->get('mailfrom');
$mailData['sitename'] = $app->get('sitename');
$mailData['siteurl'] = \Joomla\CMS\Uri\Uri::base();

$mailer = new \Joomla\CMS\Mail\MailTemplate('com_users.registration.user.admin_activated', $app->getLanguage()->getTag());
$mailer->addTemplateData($mailData);
$mailer->addRecipient($userMail);

try {
$return = $mailer->send();
} catch (\Exception $exception) {
try {
\Joomla\CMS\Log\Log::add(Text::_($exception->getMessage()), \Joomla\CMS\Log\Log::WARNING, 'jerror');

$return = false;
} catch (\RuntimeException $exception) {
$app->enqueueMessage(Text::_($exception->errorMessage()), 'warning');

$return = false;
}
}

// Check for an error.
if ($return !== true) {
$this->setError(Text::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));

return false;
}
};

PluginHelper::importPlugin($this->events_map['save']);

// Access checks.
// Activate and send the notification email
foreach ($pks as $i => $pk) {
if ($table->load($pk)) {
$old = $table->getProperties();
$allow = $user->authorise('core.edit.state', 'com_users');
$prevUserData = $table->getProperties();
$allow = $user->authorise('core.edit.state', 'com_users');

// Don't allow non-super-admin to delete a super admin
$allow = (!$iAmSuperAdmin && Access::check($pk, 'core.admin')) ? false : $allow;
// Don't allow non-super-admin to edit the active status of a super admin
$allow = (!$iAmSuperAdmin && Access::check($pk, 'core.admin')) ? false : $allow;

// Ignore activated accounts but check if we can still
// resend the notification email
if (empty($table->activation)) {
// Ignore activated accounts.
if (\is_null($table->lastvisitDate)) {
$sendMailTo($prevUserData['email']);
}

unset($pks[$i]);
} elseif ($allow) {
$table->block = 0;
Expand All @@ -506,7 +549,7 @@ public function activate(&$pks)
}

// Trigger the before save event.
$result = Factory::getApplication()->triggerEvent($this->event_before_save, array($old, false, $table->getProperties()));
$result = Factory::getApplication()->triggerEvent($this->event_before_save, array($prevUserData, false, $table->getProperties()));

if (in_array(false, $result, true)) {
// Plugin will have to raise it's own error or throw an exception.
Expand All @@ -522,6 +565,9 @@ public function activate(&$pks)

// Fire the after save event
Factory::getApplication()->triggerEvent($this->event_after_save, [$table->getProperties(), false, true, null]);

// Send the email
$sendMailTo($prevUserData['email']);
} catch (\Exception $e) {
$this->setError($e->getMessage());

Expand All @@ -530,7 +576,7 @@ public function activate(&$pks)
} else {
// Prune items that you can't change.
unset($pks[$i]);
Factory::getApplication()->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'error');
$app->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'error');
}
}
}
Expand Down Expand Up @@ -610,7 +656,7 @@ public function batch($commands, $pks, $contexts)
*/
public function batchReset($userIds, $action)
{
$userIds = ArrayHelper::toInteger($userIds);
$userIds = ArrayHelper::toInteger($userIds);

// Check if I am a Super Admin
$iAmSuperAdmin = $this->getCurrentUser()->authorise('core.admin');
Expand Down Expand Up @@ -639,11 +685,11 @@ public function batchReset($userIds, $action)
}

// Get the DB object
$db = $this->getDatabase();
$db = $this->getDatabase();

$userIds = ArrayHelper::toInteger($userIds);

$query = $db->getQuery(true);
$query = $db->getQuery(true);

// Update the reset flag
$query->update($db->quoteName('#__users'))
Expand Down Expand Up @@ -677,7 +723,7 @@ public function batchReset($userIds, $action)
*/
public function batchUser($groupId, $userIds, $action)
{
$userIds = ArrayHelper::toInteger($userIds);
$userIds = ArrayHelper::toInteger($userIds);

// Check if I am a Super Admin
$iAmSuperAdmin = $this->getCurrentUser()->authorise('core.admin');
Expand Down Expand Up @@ -721,10 +767,10 @@ public function batchUser($groupId, $userIds, $action)
// Remove the users from the group if requested.
if (isset($doDelete)) {
/*
* First we need to check that the user is part of more than one group
* otherwise we will end up with a user that is not part of any group
* unless we are moving the user to a new group.
*/
* First we need to check that the user is part of more than one group
* otherwise we will end up with a user that is not part of any group
* unless we are moving the user to a new group.
*/
if ($doDelete === 'group') {
$query = $db->getQuery(true);
$query->select($db->quoteName('user_id'))
Expand Down Expand Up @@ -865,8 +911,8 @@ public function getAssignedGroups($userId = null)
$userId = (!empty($userId)) ? $userId : (int) $this->getState('user.id');

if (empty($userId)) {
$result = array();
$form = $this->getForm();
$result = array();
$form = $this->getForm();

if ($form) {
$groupsIDs = $form->getValue('groups');
Expand Down
21 changes: 21 additions & 0 deletions administrator/components/com_users/src/View/User/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\User\User;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Component\Users\Administrator\Helper\Mfa;
Expand Down Expand Up @@ -150,6 +151,7 @@ protected function addToolbar()
$canDo = ContentHelper::getActions('com_users');
$isNew = ($this->item->id == 0);
$isProfile = $this->item->id == $user->id;
$toolbar = Toolbar::getInstance();

ToolbarHelper::title(
Text::_(
Expand Down Expand Up @@ -180,6 +182,25 @@ protected function addToolbar()
ToolbarHelper::cancel('user.cancel', 'JTOOLBAR_CLOSE');
}

$userIsActived = empty($this->item->activation);

if (!$userIsActived || \is_null($this->item->lastvisitDate)) {
$buttonText = !$userIsActived
? Text::_('COM_USERS_USER_ACTIVATE_AND_MAIL')
: Text::_('COM_USERS_USER_ACTIVATION_REMINDER');

$toolbar->standardButton('activate', $buttonText)
->buttonClass('btn activate-send-mail')
->attributes([
'data-option' => 'com_users',
'data-task' => 'user.active',
'data-format' => 'json',
'data-userid' => $this->item->id,
])
->icon('icon-mail')
->onclick('');
}

ToolbarHelper::divider();
ToolbarHelper::help('Users:_Edit_Profile');
}
Expand Down
4 changes: 3 additions & 1 deletion administrator/components/com_users/tmpl/user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
/** @var Joomla\Component\Users\Administrator\View\User\HtmlView $this */

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */

$wa = $this->document->getWebAssetManager();
$wa->useScript('keepalive')
->useScript('form.validate');
->useScript('form.validate')
->useScript('com_users.active-user-send-mail');

$input = Factory::getApplication()->getInput();

Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ COM_USERS_USERS_N_ITEMS_DELETED="%d users deleted."
COM_USERS_USERS_N_ITEMS_DELETED_1="User deleted."
COM_USERS_USERS_TABLE_CAPTION="Users"
COM_USERS_USER_ACCOUNT_DETAILS="Account Details"
COM_USERS_USER_ACTIVATE_AND_MAIL="Activate and send email"
COM_USERS_USER_ACTIVATION_REMINDER="Send activation reminder"
COM_USERS_USER_BACKUPCODE="Backup Code"
COM_USERS_USER_BACKUPCODES="Backup Codes"
COM_USERS_USER_BACKUPCODES_CAPTIVE_PROMPT="If you do not have access to your usual Multi-factor Authentication method use any of your Backup Codes in the field below. Please remember that this emergency backup code cannot be reused."
Expand Down
Loading