From 41ca54c44ad32b7382f4867516885fd8cd34dff6 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kisseberth" Date: Fri, 10 May 2024 13:36:47 -0700 Subject: [PATCH] [HZ-264] fixed errors in email confirmation after email change, then reverted to using existing helper function --- .../com_members/helpers/utility.php | 3 ++- .../com_members/site/controllers/profiles.php | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core/components/com_members/helpers/utility.php b/core/components/com_members/helpers/utility.php index 3763523e0b0..013cfa1eb71 100644 --- a/core/components/com_members/helpers/utility.php +++ b/core/components/com_members/helpers/utility.php @@ -199,7 +199,7 @@ public static function genemailconfirm() * @param object $xregistration * @return bool */ - public static function sendConfirmEmail($user, $xregistration) + public static function sendConfirmEmail($user, $xregistration, $new = true) { $baseURL = rtrim(Request::root(), '/'); @@ -216,6 +216,7 @@ public static function sendConfirmEmail($user, $xregistration) $eview->xprofile = $user; $eview->baseURL = $baseURL; $eview->xregistration = $xregistration; + $eview->new = $new; $msg = new \Hubzero\Mail\Message(); $msg->setSubject($subject) diff --git a/core/components/com_members/site/controllers/profiles.php b/core/components/com_members/site/controllers/profiles.php index fb43734ede1..60b7601360e 100644 --- a/core/components/com_members/site/controllers/profiles.php +++ b/core/components/com_members/site/controllers/profiles.php @@ -1723,7 +1723,19 @@ public function saveTask() // Send a new confirmation code AFTER we've successfully saved the changes to the e-mail address if ($email != $oldemail) { - $this->_sendConfirmationCode($member->get('username'), $email, $confirm); + $result = \Components\Members\Helpers\Utility::sendConfirmEmail($user, null, false); + + if ($result) + { + Notify::success('A confirmation email has been sent to "'. htmlentities($email, ENT_COMPAT, 'UTF-8') .'". You must click the link in that email to re-activate your account.'); + } + else + { + Notify::error('An error occurred emailing "'. htmlentities($email, ENT_COMPAT, 'UTF-8') .'" your confirmation.'); + } + + //$this->_sendConfirmationCode($member->get('username'), $email, $confirm, $member->get('registerDate'),$member->get('name')); + Event::trigger('onUserAfterChangeEmail', array($member->toArray())); } @@ -1757,7 +1769,7 @@ public function saveTask() * @param string $confirm Confirmation code * @return boolean */ - private function _sendConfirmationCode($login, $email, $confirm) + private function _sendConfirmationCode($login, $email, $confirm, $name, $registerDate) { // Email subject $subject = Config::get('sitename') .' account email confirmation'; @@ -1767,12 +1779,15 @@ private function _sendConfirmationCode($login, $email, $confirm) 'name' => 'emails', 'layout' => 'confirm' )); + $eview->set('option', $this->_option) ->set('sitename', Config::get('sitename')) ->set('login', $login) ->set('email', $email) ->set('confirm', $confirm) - ->set('baseURL', Request::base()); + ->set('baseURL', Request::base()) + ->set('registerDate', $registerDate) + ->set('name', $name); $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message);