Skip to content

Commit e10a351

Browse files
authored
[5.4] Fix registration error notification (joomla#45656)
On email error the user is no longer redirected to the registration form
1 parent b0d8353 commit e10a351

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

components/com_users/src/Model/RegistrationModel.php

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Joomla\Component\Users\Site\Model;
1212

1313
use Joomla\CMS\Application\ApplicationHelper;
14+
use Joomla\CMS\Application\CMSApplicationInterface;
1415
use Joomla\CMS\Component\ComponentHelper;
1516
use Joomla\CMS\Date\Date;
1617
use Joomla\CMS\Factory;
@@ -462,6 +463,7 @@ public function register($temp)
462463
return false;
463464
}
464465

466+
// From this moment the user is registered, so we don't return false anymore
465467
$app = Factory::getApplication();
466468
$db = $this->getDatabase();
467469
$query = $db->getQuery(true);
@@ -514,18 +516,15 @@ public function register($temp)
514516
$mailer->addTemplateData($data);
515517
$mailer->addRecipient($data['email']);
516518
$mailer->addUnsafeTags(['username', 'password_clear', 'name']);
519+
517520
$return = $mailer->send();
518521
} catch (\Exception $exception) {
519-
try {
520-
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'jerror');
522+
$return = false;
521523

522-
$return = false;
524+
try {
525+
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'joomla_registration');
523526
} catch (\RuntimeException $exception) {
524-
Factory::getApplication()->enqueueMessage(Text::_($exception->errorMessage()), 'warning');
525-
526-
$this->setError(Text::_('COM_MESSAGES_ERROR_MAIL_FAILED'));
527-
528-
$return = false;
527+
// We set the error message below but we don't need to notify the user that we can't add logs
529528
}
530529
}
531530

@@ -543,9 +542,7 @@ public function register($temp)
543542
try {
544543
$rows = $db->loadObjectList();
545544
} catch (\RuntimeException $e) {
546-
$this->setError(Text::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()));
547-
548-
return false;
545+
$rows = [];
549546
}
550547

551548
// Send mail to all superadministrators id
@@ -561,31 +558,21 @@ public function register($temp)
561558
$mailer->addTemplateData($data);
562559
$mailer->addRecipient($row->email);
563560
$mailer->addUnsafeTags(['username', 'name']);
564-
$return = $mailer->send();
561+
562+
$mailer->send();
565563
} catch (\Exception $exception) {
566564
try {
567-
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'jerror');
568-
569-
$return = false;
565+
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'joomla_registration');
570566
} catch (\RuntimeException $exception) {
571-
Factory::getApplication()->enqueueMessage(Text::_($exception->errorMessage()), 'warning');
572-
573-
$return = false;
567+
// No message to frontend user
574568
}
575569
}
576-
577-
// Check for an error.
578-
if ($return !== true) {
579-
$this->setError(Text::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
580-
581-
return false;
582-
}
583570
}
584571
}
585572

586573
// Check for an error.
587574
if ($return !== true) {
588-
$this->setError(Text::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'));
575+
$app->enqueueMessage(Text::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'), CMSApplicationInterface::MSG_WARNING);
589576

590577
// Send a system message to administrators receiving system mails
591578
$db = $this->getDatabase();
@@ -599,9 +586,12 @@ public function register($temp)
599586
try {
600587
$userids = $db->loadColumn();
601588
} catch (\RuntimeException $e) {
602-
$this->setError(Text::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()));
589+
$userids = [];
603590

604-
return false;
591+
try {
592+
Log::add(Text::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), Log::WARNING, 'joomla_registration');
593+
} catch (\RuntimeException $exception) {
594+
}
605595
}
606596

607597
if (\count($userids) > 0) {
@@ -634,14 +624,13 @@ public function register($temp)
634624
try {
635625
$db->execute();
636626
} catch (\RuntimeException $e) {
637-
$this->setError(Text::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()));
638-
639-
return false;
627+
try {
628+
Log::add(Text::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), Log::WARNING, 'joomla_registration');
629+
} catch (\RuntimeException $exception) {
630+
}
640631
}
641632
}
642633
}
643-
644-
return false;
645634
}
646635

647636
if ($useractivation == 1) {

0 commit comments

Comments
 (0)