Skip to content

Commit

Permalink
success message + reviewers changes + lenguages strings
Browse files Browse the repository at this point in the history
  • Loading branch information
carlitorweb committed Jan 18, 2023
1 parent 5da1653 commit 5c5c018
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,31 @@ protected function postSaveHook(BaseDatabaseModel $model, $validData = array())

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

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

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

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

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

echo new JsonResponse($responseData, $responseMessage, $responseError);
$responseMessage = \Joomla\CMS\Factory::getApplication()->getMessageQueue();

echo new JsonResponse(null, $responseMessage, $responseError);
}
}
45 changes: 28 additions & 17 deletions administrator/components/com_users/src/Model/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,27 +472,33 @@ public function block(&$pks, $value = 1)
*/
public function activate(&$pks)
{
$app = Factory::getApplication();
$user = $app->getIdentity();
$app = Factory::getApplication();
$user = $app->getIdentity();

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

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

// Compile the user activated notification mail default values.
$mailData = [];
$mailData['siteurl'] = \Joomla\CMS\Uri\Uri::root();
$mailData['fromname'] = $app->get('fromname');
$mailData['mailfrom'] = $app->get('mailfrom');
$mailData['sitename'] = $app->get('sitename');

// 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();
// Load com_users site language strings, the mail template use it
$app->getLanguage()->load('com_users', JPATH_SITE);

$sendMailTo = function ($userData) use ($app, $mailData) {
$mailData['name'] = $userData['name'];
$mailData['username'] = $userData['username'];

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

try {
$return = $mailer->send();
Expand All @@ -502,18 +508,21 @@ public function activate(&$pks)

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

$return = false;
}
}

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

return false;
}

$app->enqueueMessage(Text::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_SUCCESS'), $app::MSG_INFO);
return true;
};

PluginHelper::importPlugin($this->events_map['save']);
Expand All @@ -531,7 +540,7 @@ public function activate(&$pks)
// resend the notification email
if (empty($table->activation)) {
if (\is_null($table->lastvisitDate)) {
$sendMailTo($prevUserData['email']);
$sendMailTo($prevUserData);
}

unset($pks[$i]);
Expand Down Expand Up @@ -566,7 +575,9 @@ public function activate(&$pks)
Factory::getApplication()->triggerEvent($this->event_after_save, [$table->getProperties(), false, true, null]);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Joomla\CMS\MVC\View\GenericDataException;
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\Toolbar\ToolbarHelper;
use Joomla\CMS\User\User;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Component\Users\Administrator\Helper\Mfa;
Expand Down
1 change: 1 addition & 0 deletions language/en-GB/com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ COM_USERS_REGISTRATION_ACL_ADMIN_ACTIVATION="Please log in to confirm that you a
COM_USERS_REGISTRATION_ACL_ADMIN_ACTIVATION_PERMISSIONS="You are not authorised to activate new accounts, please log in with a privileged account."
COM_USERS_REGISTRATION_ACTIVATE_SUCCESS="Your Account has been activated. You can now log in using the username and password you chose during the registration."
COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED="An error was encountered while sending activation notification email"
COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_SUCCESS="The user has been notified about his account is activated."
COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED="Failed to save activation data: %s"
COM_USERS_REGISTRATION_ADMINACTIVATE_SUCCESS="The user's account has been activated and the user has been notified about it."
COM_USERS_REGISTRATION_COMPLETE_ACTIVATE="Your account has been created and an activation link has been sent to the email address you entered. Note that you must activate the account by selecting the activation link when you get the email before you can login."
Expand Down

0 comments on commit 5c5c018

Please sign in to comment.