From 2297524f0ff8695ba636c5c8165d1105317c0be8 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 6 Nov 2014 16:20:58 -0500 Subject: [PATCH] benefits: Validate local part of email alias. * CRM/Memberdashboard/Page/Benefits.php (CRM_Memberdashboard_Page_Benefits) [add]: Validate local part. [edit]: Likewise. --- CRM/Memberdashboard/Page/Benefits.php | 41 ++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/CRM/Memberdashboard/Page/Benefits.php b/CRM/Memberdashboard/Page/Benefits.php index 9c82490..fc84c96 100644 --- a/CRM/Memberdashboard/Page/Benefits.php +++ b/CRM/Memberdashboard/Page/Benefits.php @@ -48,22 +48,27 @@ class CRM_Memberdashboard_Page_Benefits extends CRM_Memberdashboard_Page { $count = CRM_Memberdashboard_BAO_EmailAlias::countForContact($contactId); if(CRM_Utils_Rule::email($forward)) { - if($count < MEMBERDASHBOARD_MAX_EMAIL_ALIASES) { - try { - $params = array( - 'contact_id' => $contactId, - 'localpart' => $localpart, - 'forward' => $forward - ); - CRM_Memberdashboard_BAO_EmailAlias::create($params); - CRM_Core_Session::setStatus('Email alias added!', - 'Success', 'success'); - } catch (Exception $e) { - CRM_Core_Session::setStatus('Failed to create email alias', + if(CRM_Utils_Rule::email("$localpart@example.com")) { + if($count < MEMBERDASHBOARD_MAX_EMAIL_ALIASES) { + try { + $params = array( + 'contact_id' => $contactId, + 'localpart' => $localpart, + 'forward' => $forward + ); + CRM_Memberdashboard_BAO_EmailAlias::create($params); + CRM_Core_Session::setStatus('Email alias added!', + 'Success', 'success'); + } catch (Exception $e) { + CRM_Core_Session::setStatus('Failed to create email alias', + 'Error', 'error'); + } + } else { + CRM_Core_Session::setStatus('You cannot have more than 5 email aliases', 'Error', 'error'); } } else { - CRM_Core_Session::setStatus('You cannot have more than 5 email aliases', + CRM_Core_Session::setStatus('Invalid local part', 'Error', 'error'); } } else { @@ -94,9 +99,13 @@ class CRM_Memberdashboard_Page_Benefits extends CRM_Memberdashboard_Page { if($alias->contactId != $this->contact['id']) { $error .= '
  • You cannot alter email aliases that don\'t belong to you!
  • '; } else if(CRM_Utils_Rule::email($forward)) { - $alias->localpart = $localpart; - $alias->forward = $forward; - $alias->save(); + if(CRM_Utils_Rule::email("$localpart@example.com")) { + $alias->localpart = $localpart; + $alias->forward = $forward; + $alias->save(); + } else { + $error .= "
  • Invalid local part: $localpart
  • "; + } } else { $error .= "
  • Invalid email forwarding address: $forward
  • "; } -- 2.25.1