From 8f74f4af7b6200825c601dbec01e0c4da437a017 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Thu, 2 Sep 2021 12:08:15 +0100 Subject: [PATCH] Remove requirement to verify email on opt out --- CRM/Mailing/Form/Optout.php | 78 +++++++++++++-------------- templates/CRM/Mailing/Form/Optout.tpl | 23 +++----- 2 files changed, 44 insertions(+), 57 deletions(-) diff --git a/CRM/Mailing/Form/Optout.php b/CRM/Mailing/Form/Optout.php index 07b8a2566e..39707570e9 100644 --- a/CRM/Mailing/Form/Optout.php +++ b/CRM/Mailing/Form/Optout.php @@ -16,18 +16,40 @@ */ class CRM_Mailing_Form_Optout extends CRM_Core_Form { - public function preProcess() { - - $this->_type = 'optout'; + /** + * Prevent people double-submitting the form (e.g. by double-clicking). + * https://lab.civicrm.org/dev/core/-/issues/1773 + * + * @var bool + */ + public $submitOnce = TRUE; + + /** + * @var int + */ + private $_job_id; + + /** + * @var int + */ + private $_queue_id; + + /** + * @var string + */ + private $_hash; + + /** + * @var string + */ + private $_email; + public function preProcess() { $this->_job_id = $job_id = CRM_Utils_Request::retrieve('jid', 'Integer', $this); $this->_queue_id = $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer', $this); $this->_hash = $hash = CRM_Utils_Request::retrieve('h', 'String', $this); - if (!$job_id || - !$queue_id || - !$hash - ) { + if (!$job_id || !$queue_id || !$hash) { throw new CRM_Core_Exception(ts("Missing input parameters")); } @@ -49,9 +71,6 @@ class CRM_Mailing_Form_Optout extends CRM_Core_Form { CRM_Utils_System::addHTMLHead(''); $this->setTitle(ts('Opt Out Confirmation')); - $this->add('text', 'email_confirm', ts('Verify email address to opt out:')); - $this->addRule('email_confirm', ts('Email address is required to opt out.'), 'required'); - $buttons = [ [ 'type' => 'next', @@ -68,42 +87,17 @@ class CRM_Mailing_Form_Optout extends CRM_Core_Form { } public function postProcess() { - - $values = $this->exportValues(); - - // check if EmailTyped matches Email address - $result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE); - - $job_id = $this->_job_id; - $queue_id = $this->_queue_id; - $hash = $this->_hash; - - $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1"); + $confirmURL = CRM_Utils_System::url("civicrm/mailing/optout", "reset=1&jid={$this->_job_id}&qid={$this->_queue_id}&h={$this->_hash}&confirm=1"); $this->assign('confirmURL', $confirmURL); - $session = CRM_Core_Session::singleton(); - $session->pushUserContext($confirmURL); - - if ($result == TRUE) { - // Email address verified - if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) { - CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id); - } - - $statusMsg = ts('%1 opt out confirmed.', - [1 => $values['email_confirm']] - ); - - CRM_Core_Session::setStatus($statusMsg, '', 'success'); - } - elseif ($result == FALSE) { - // Email address not verified - $statusMsg = ts('%1 is not associated with this opt out request.', - [1 => $values['email_confirm']] - ); + CRM_Core_Session::singleton()->pushUserContext($confirmURL); - CRM_Core_Session::setStatus($statusMsg, '', 'error'); + // Email address verified + if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($this->_job_id, $this->_queue_id, $this->_hash)) { + CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($this->_queue_id, NULL, TRUE, $this->_job_id); } + $statusMsg = ts('%1 opt out confirmed.', [1 => CRM_Utils_String::maskEmail($this->_email)]); + CRM_Core_Session::setStatus($statusMsg, '', 'success'); } } diff --git a/templates/CRM/Mailing/Form/Optout.tpl b/templates/CRM/Mailing/Form/Optout.tpl index d862daaaf7..e5286a508a 100644 --- a/templates/CRM/Mailing/Form/Optout.tpl +++ b/templates/CRM/Mailing/Form/Optout.tpl @@ -9,25 +9,18 @@ *}
+

{ts}You are requesting to opt out this email address from all mailing lists:{/ts}

+

{$email_masked}

-

{ts}You are requesting to opt out this email address from all mailing lists:{/ts}

-

{$email_masked}

- -

{ts}If this is not your email address, there is no need to do anything. You have not been added to any mailing lists. If this is your email address and you wish to opt out please enter your email address below for verification purposes:{/ts}

- - - - - - - -
{$form.email_confirm.label}{$form.email_confirm.html} -
+

+ {ts}If this is not your email address, there is no need to do anything. You have not been added to any mailing lists.{/ts} + {ts}If this is your email address and you wish to opt out please click the Opt Out button to confirm.{/ts} +

- {include file="CRM/common/formButtons.tpl" location="bottom"} + {include file="CRM/common/formButtons.tpl" location="bottom"}
-
+
-- 2.25.1