benefits: Validate local part of email alias.
authorDavid Thompson <davet@gnu.org>
Thu, 6 Nov 2014 21:20:58 +0000 (16:20 -0500)
committerDavid Thompson <davet@gnu.org>
Thu, 6 Nov 2014 21:20:58 +0000 (16:20 -0500)
* CRM/Memberdashboard/Page/Benefits.php (CRM_Memberdashboard_Page_Benefits)
  [add]: Validate local part.
  [edit]: Likewise.

CRM/Memberdashboard/Page/Benefits.php

index 9c8249061870e6bb8ea7ca310b6956b3ed3429cc..fc84c96e7566fae472d713c05e49621820788f4b 100644 (file)
@@ -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 .= '<li>You cannot alter email aliases that don\'t belong to you!</li>';
         } 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 .= "<li>Invalid local part: $localpart</li>";
+          }
         } else {
           $error .= "<li>Invalid email forwarding address: $forward</li>";
         }