Example #1
0
 /**
  * Testing setOptions
  */
 public function testSetOptions()
 {
     $this->_validator->setOptions(array('messages' => array(Zend_Validate_EmailAddress::INVALID => 'TestMessage')));
     $messages = $this->_validator->getMessageTemplates();
     $this->assertEquals('TestMessage', $messages[Zend_Validate_EmailAddress::INVALID]);
     $oldHostname = $this->_validator->getHostnameValidator();
     $this->_validator->setOptions(array('hostname' => new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL)));
     $hostname = $this->_validator->getHostnameValidator();
     $this->assertNotEquals($oldHostname, $hostname);
 }
Example #2
0
 /**
  * SW-8258 - check if email addresses with new domains like .berlin are valid
  */
 public function testValidEmailAddresses()
 {
     $emailAddresses = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
     $invalidEmailAddresses = array('test', 'test@example', 'test@.de', '@example', '@example.de', '@.', ' @ .de');
     $validator = new Zend_Validate_EmailAddress();
     $validator->getHostnameValidator()->setValidateTld(false);
     foreach ($emailAddresses as $email) {
         $this->assertTrue($validator->isValid($email));
     }
     foreach ($invalidEmailAddresses as $email) {
         $this->assertFalse($validator->isValid($email));
     }
 }
 public function validateEmails($value)
 {
     // Not string?
     if (!is_string($value) || empty($value)) {
         return false;
     }
     // Validate emails
     $validate = new Zend_Validate_EmailAddress();
     $validate->getHostnameValidator()->setValidateTld(false);
     $emails = array_unique(array_filter(array_map('trim', preg_split("/[\\s,]+/", $value))));
     if (empty($emails)) {
         return false;
     }
     foreach ($emails as $email) {
         if (!$validate->isValid($email)) {
             return false;
         }
     }
     return true;
 }
Example #4
0
 public function takenAction()
 {
     $username = $this->_getParam('username');
     $email = $this->_getParam('email');
     // Sent both or neither username/email
     if ((bool) $username == (bool) $email) {
         $this->view->status = false;
         $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid param count');
         return;
     }
     // Username must be alnum
     if ($username) {
         $validator = new Zend_Validate_Alnum();
         if (!$validator->isValid($username)) {
             $this->view->status = false;
             $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid param value');
             //$this->view->errors = $validator->getErrors();
             return;
         }
         $table = Engine_Api::_()->getItemTable('user');
         $row = $table->fetchRow($table->select()->where('username = ?', $username)->limit(1));
         $this->view->status = true;
         $this->view->taken = $row !== null;
         return;
     }
     if ($email) {
         $validator = new Zend_Validate_EmailAddress();
         $validator->getHostnameValidator()->setValidateTld(false);
         if (!$validator->isValid($email)) {
             $this->view->status = false;
             $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid param value');
             //$this->view->errors = $validator->getErrors();
             return;
         }
         $table = Engine_Api::_()->getItemTable('user');
         $row = $table->fetchRow($table->select()->where('email = ?', $email)->limit(1));
         $this->view->status = true;
         $this->view->taken = $row !== null;
         return;
     }
 }
 /**
  * @param $filePath
  */
 public function importNewsletter($filePath)
 {
     $results = new Shopware_Components_CsvIterator($filePath, ';');
     $insertCount = 0;
     $updateCount = 0;
     $errors = array();
     $emailValidator = new Zend_Validate_EmailAddress();
     $emailValidator->getHostnameValidator()->setValidateTld(false);
     foreach ($results as $newsletterData) {
         if (empty($newsletterData['email'])) {
             $errors[] = "Empty email field";
             continue;
         }
         if (!$emailValidator->isValid($newsletterData['email'])) {
             $errors[] = "Invalid email address: " . $newsletterData['email'];
             continue;
         }
         // Set newsletter recipient/group
         $group = null;
         if ($newsletterData['group']) {
             $group = $this->getGroupRepository()->findOneByName($newsletterData['group']);
         }
         if (!$group && $newsletterData['group']) {
             $group = new Group();
             $group->setName($newsletterData['group']);
             $this->getManager()->persist($group);
         } elseif (!$group && ($groupId = Shopware()->Config()->get("sNEWSLETTERDEFAULTGROUP"))) {
             $group = $this->getGroupRepository()->findOneBy($groupId);
         } elseif (!$group) {
             // If no group is specified and no default config exists, don't import the address
             // This should never actually happen, as a default should always exist
             // but its better to be safe than sorry
             continue;
         }
         //Create/Update the Address entry
         $recipient = $this->getAddressRepository()->findOneByEmail($newsletterData['email']) ?: new Address();
         if ($recipient->getId()) {
             $updateCount++;
         } else {
             $insertCount++;
         }
         $recipient->setEmail($newsletterData['email']);
         $recipient->setIsCustomer(!empty($newsletterData['userID']));
         //Only set the group if it was explicitly provided or it's a new entry
         if ($group && ($newsletterData['group'] || !$recipient->getId())) {
             $recipient->setNewsletterGroup($group);
         }
         $this->getManager()->persist($recipient);
         $this->getManager()->flush();
         //Create/Update the ContactData entry
         $contactData = $this->getContactDataRepository()->findOneByEmail($newsletterData['email']) ?: new ContactData();
         //sanitize to avoid setting fields the user's not supposed to access
         unset($newsletterData['added']);
         unset($newsletterData['deleted']);
         $contactData->fromArray($newsletterData);
         //Only set the group if it was explicitly provided or it's a new entry
         if ($group && ($newsletterData['group'] || !$contactData->getId())) {
             $contactData->setGroupId($group->getId());
         }
         $contactData->setAdded(new \DateTime());
         $this->getManager()->persist($contactData);
         $this->getManager()->flush();
     }
     if (!empty($errors)) {
         $message = implode("<br>\n", $errors);
         echo json_encode(array('success' => false, 'message' => sprintf("Errors: {$message}")));
         return;
     }
     echo json_encode(array('success' => true, 'message' => sprintf("Imported: %s. Updated: %s.", $insertCount, $updateCount)));
     return;
 }
Example #6
0
 /**
  * Checks if the given email isn't already registered
  */
 public function ajaxValidateEmailAction()
 {
     $error_flags = array();
     $error_messages = array();
     $validator = new Zend_Validate_EmailAddress();
     $validator->getHostnameValidator()->setValidateTld(false);
     if (empty($this->post['personal']['email'])) {
     } elseif (!$validator->isValid($this->post['personal']['email'])) {
         $error_messages[] = Shopware()->Snippets()->getNamespace("frontend")->get('RegisterAjaxEmailNotValid', 'Please enter a valid mail address.', true);
         $error_flags['email'] = true;
         if (!empty($this->post['personal']['emailConfirmation'])) {
             $error_flags['emailConfirmation'] = true;
         }
     } elseif (empty($this->post['personal']['skipLogin']) && $this->admin->sGetUserByMail($this->post['personal']['email'])) {
         $error_messages[] = Shopware()->Snippets()->getNamespace("frontend")->get('RegisterAjaxEmailForgiven', 'This mail address is already in use.', true);
         $error_flags['email'] = true;
         if (!empty($this->post['personal']['emailConfirmation'])) {
             $error_flags['emailConfirmation'] = true;
         }
     } elseif (empty($this->post['personal']['emailConfirmation'])) {
         $error_flags['email'] = false;
     } elseif ($this->post['personal']['emailConfirmation'] != $this->post['personal']['email']) {
         $error_messages[] = Shopware()->Snippets()->getNamespace("frontend")->get('RegisterAjaxEmailNotEqual', 'The mail addresses you have entered are not equal.', true);
         $error_flags['email'] = true;
         $error_flags['emailConfirmation'] = true;
     } else {
         $error_flags['email'] = false;
         $error_flags['emailConfirmation'] = false;
     }
     foreach ($error_messages as $key => $error_message) {
         $error_messages[$key] = $this->View()->fetch('string:' . $error_message);
     }
     echo Zend_Json::encode(array('success' => empty($error_messages), 'error_flags' => $error_flags, 'error_messages' => $error_messages));
 }
 /**
  * @group ZF-11239
  */
 public function testNotSetHostnameValidator()
 {
     $hostname = $this->_validator->getHostnameValidator();
     $this->assertTrue($hostname instanceof Zend_Validate_Hostname);
 }
Example #8
0
 /**
  * Called on register for status updates
  * Check user email address and send double optin to confirm the email
  * @static
  * @param Enlight_Event_EventArgs $args
  * @return
  */
 public static function onNotifyAction(Enlight_Event_EventArgs $args)
 {
     $args->setProcessed(true);
     $action = $args->getSubject();
     $id = (int) $action->Request()->sArticle;
     $email = $action->Request()->sNotificationEmail;
     $sError = false;
     $action->View()->NotifyEmailError = false;
     $notifyOrderNumber = $action->Request()->notifyOrdernumber;
     if (!empty($notifyOrderNumber)) {
         $validator = new Zend_Validate_EmailAddress();
         $validator->getHostnameValidator()->setValidateTld(false);
         if (empty($email) || !$validator->isValid($email)) {
             $sError = true;
             $action->View()->NotifyEmailError = true;
         } elseif (!empty($notifyOrderNumber)) {
             if (!empty(Shopware()->Session()->sNotificatedArticles)) {
                 if (in_array($notifyOrderNumber, Shopware()->Session()->sNotificatedArticles)) {
                     $sError = true;
                     $action->View()->ShowNotification = false;
                     $action->View()->NotifyAlreadyRegistered = true;
                 } else {
                     Shopware()->Session()->sNotificatedArticles[] = $notifyOrderNumber;
                 }
             } else {
                 Shopware()->Session()->sNotificatedArticles = array($notifyOrderNumber);
             }
         } else {
             $sError = true;
         }
         if (!$sError) {
             $AlreadyNotified = Shopware()->Db()->fetchRow('
                 SELECT *  FROM `s_articles_notification`
                 WHERE `ordernumber`=?
                 AND `mail` = ?
                 AND send = 0
             ', array($notifyOrderNumber, $email));
             if (empty($AlreadyNotified)) {
                 $action->View()->NotifyAlreadyRegistered = false;
                 $hash = md5(uniqid(rand()));
                 $link = $action->Front()->Router()->assemble(array('sViewport' => 'detail', 'sArticle' => $id, 'sNotificationConfirmation' => $hash, 'sNotify' => '1', 'action' => 'notifyConfirm'));
                 $name = Shopware()->Modules()->Articles()->sGetArticleNameByOrderNumber($notifyOrderNumber);
                 $basePath = $action->Front()->Router()->assemble(array('sViewport' => 'index'));
                 Shopware()->System()->_POST['sLanguage'] = Shopware()->System()->sLanguageData[Shopware()->System()->sLanguage]['isocode'];
                 Shopware()->System()->_POST['sShopPath'] = $basePath . Shopware()->Config()->sBASEFILE;
                 $sql = '
                     INSERT INTO s_core_optin (datum, hash, data)
                     VALUES (NOW(), ?, ?)
                 ';
                 Shopware()->Db()->query($sql, array($hash, serialize(Shopware()->System()->_POST->toArray())));
                 $context = array('sConfirmLink' => $link, 'sArticleName' => $name);
                 $mail = Shopware()->TemplateMail()->createMail('sACCEPTNOTIFICATION', $context);
                 $mail->addTo($email);
                 $mail->send();
                 Shopware()->Session()->sNotifcationArticleWaitingForOptInApprovement[$notifyOrderNumber] = true;
             } else {
                 $action->View()->NotifyAlreadyRegistered = true;
             }
         }
     }
     return $action->forward('index');
 }
Example #9
0
 /**
  * Determine if an email is valid (does not validate TLDs).
  *
  * @param string $email
  *
  * @return bool
  */
 public static function isEmailValid($email)
 {
     $validator = new Zend_Validate_EmailAddress();
     $validator->getHostnameValidator()->setValidateTld(false)->setValidateIdn(false);
     return $validator->isValid($email);
 }
Example #10
0
 public function indexAction()
 {
     if (empty($this->Request()->sDetails)) {
         $id = $this->Request()->sArticle;
     } else {
         $id = $this->Request()->sDetails;
     }
     if (empty($id)) {
         return $this->forward("index", "index");
     }
     // Get Article-Information
     $sArticle = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, intval($id));
     if (empty($sArticle["articleName"])) {
         return $this->forward("index", "index");
     }
     if ($this->Request()->getPost("sMailTo")) {
         $variables["sError"] = false;
         if (!$this->Request()->getPost("sName")) {
             $variables["sError"] = true;
         }
         if (!$this->Request()->getPost("sMail")) {
             $variables["sError"] = true;
         }
         if (!$this->Request()->getPost("sRecipient")) {
             $variables["sError"] = true;
         }
         if (preg_match("/;/", $this->Request()->getPost("sRecipient")) || strlen($this->Request()->getPost("sRecipient") >= 50)) {
             $variables["sError"] = true;
         }
         $validator = new Zend_Validate_EmailAddress();
         $validator->getHostnameValidator()->setValidateTld(false);
         if (!$validator->isValid($this->Request()->getPost("sRecipient"))) {
             $variables["sError"] = true;
         }
         if (!empty(Shopware()->Config()->CaptchaColor)) {
             $captcha = str_replace(' ', '', strtolower($this->Request()->sCaptcha));
             $rand = $this->Request()->getPost('sRand');
             if (empty($rand) || $captcha != substr(md5($rand), 0, 5)) {
                 $variables["sError"] = true;
             }
         }
         if ($variables["sError"] == false) {
             // Prepare eMail
             $sArticle["linkDetails"] = $this->Front()->Router()->assemble(array('sViewport' => 'detail', 'sArticle' => $sArticle["articleID"]));
             $context = array('sName' => $this->sSYSTEM->_POST["sName"], 'sArticle' => html_entity_decode($sArticle["articleName"]), 'sLink' => $sArticle["linkDetails"]);
             if ($this->sSYSTEM->_POST["sComment"]) {
                 $context['sComment'] = strip_tags(html_entity_decode($this->sSYSTEM->_POST["sComment"]));
             } else {
                 $context['sComment'] = '';
             }
             $mail = Shopware()->TemplateMail()->createMail('sTELLAFRIEND', $context, null, array("fromMail" => $this->sSYSTEM->_POST["sMail"], "fromName" => $this->sSYSTEM->_POST["sName"]));
             $mail->addTo($this->sSYSTEM->_POST["sRecipient"]);
             $mail->send();
             $this->View()->sSuccess = true;
             $url = $this->Front()->Router()->assemble(array('controller' => 'tellafriend', 'action' => 'success'));
             $this->redirect($url);
         } else {
             $this->View()->sError = true;
             $this->View()->sName = $this->Request()->getPost("sName");
             $this->View()->sMail = $this->Request()->getPost("sMail");
             $this->View()->sRecipient = $this->Request()->getPost("sRecipient");
             $this->View()->sComment = $this->Request()->getPost("sComment");
         }
     }
     $this->View()->rand = md5(uniqid(rand()));
     $this->View()->sArticle = $sArticle;
 }
Example #11
0
 /**
  * Rating action method
  *
  * Save and review the product rating
  */
 public function ratingAction()
 {
     $id = (int) $this->Request()->sArticle;
     if (empty($id)) {
         return $this->forward('error');
     }
     $article = Shopware()->Modules()->Articles()->sGetArticleNameByArticleId($id);
     if (empty($article)) {
         return $this->forward('error');
     }
     $voteConfirmed = false;
     if ($hash = $this->Request()->sConfirmation) {
         $getVote = Shopware()->Db()->fetchRow('
             SELECT * FROM s_core_optin WHERE hash = ?
         ', array($hash));
         if (!empty($getVote['data'])) {
             Shopware()->System()->_POST = unserialize($getVote['data']);
             $voteConfirmed = true;
             Shopware()->Db()->query('DELETE FROM s_core_optin WHERE hash = ?', array($hash));
         }
     }
     if (empty(Shopware()->System()->_POST['sVoteName'])) {
         $sErrorFlag['sVoteName'] = true;
     }
     if (empty(Shopware()->System()->_POST['sVoteSummary'])) {
         $sErrorFlag['sVoteSummary'] = true;
     }
     if (!empty(Shopware()->Config()->CaptchaColor) && !$voteConfirmed) {
         $captcha = str_replace(' ', '', strtolower($this->Request()->sCaptcha));
         $rand = $this->Request()->getPost('sRand');
         if (empty($rand) || $captcha != substr(md5($rand), 0, 5)) {
             $sErrorFlag['sCaptcha'] = true;
         }
     }
     $validator = new Zend_Validate_EmailAddress();
     $validator->getHostnameValidator()->setValidateTld(false);
     if (!empty(Shopware()->Config()->sOPTINVOTE) && (empty(Shopware()->System()->_POST['sVoteMail']) || !$validator->isValid(Shopware()->System()->_POST['sVoteMail']))) {
         $sErrorFlag['sVoteMail'] = true;
     }
     if (empty($sErrorFlag)) {
         if (!empty(Shopware()->Config()->sOPTINVOTE) && !$voteConfirmed && empty(Shopware()->Session()->sUserId)) {
             $hash = md5(uniqid(rand()));
             $sql = '
                 INSERT INTO s_core_optin (datum, hash, data)
                 VALUES (NOW(), ?, ?)
             ';
             Shopware()->Db()->query($sql, array($hash, serialize(Shopware()->System()->_POST->toArray())));
             $link = $this->Front()->Router()->assemble(array('sViewport' => 'detail', 'action' => 'rating', 'sArticle' => $id, 'sConfirmation' => $hash));
             $context = array('sConfirmLink' => $link, 'sArticle' => array('articleName' => $article));
             $mail = Shopware()->TemplateMail()->createMail('sOPTINVOTE', $context);
             $mail->addTo($this->Request()->getParam('sVoteMail'));
             $mail->Send();
         } else {
             unset(Shopware()->Config()->sOPTINVOTE);
             Shopware()->Modules()->Articles()->sSaveComment($id);
         }
     } else {
         $this->View()->sFormData = Shopware()->System()->_POST->toArray();
         $this->View()->sErrorFlag = $sErrorFlag;
     }
     $this->View()->sAction = 'ratingAction';
     $this->forward('index');
 }
Example #12
0
 /**
  * Rating action method
  *
  * Save and review the blog comment and rating
  */
 public function ratingAction()
 {
     $blogArticleId = intval($this->Request()->blogArticle);
     if (!empty($blogArticleId)) {
         $blogArticleQuery = $this->getRepository()->getDetailQuery($blogArticleId);
         $blogArticleData = $blogArticleQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
         if ($hash = $this->Request()->sConfirmation) {
             //customer confirmed the link in the mail
             $commentConfirmQuery = $this->getCommentConfirmRepository()->getConfirmationByHashQuery($hash);
             $getComment = $commentConfirmQuery->getOneOrNullResult();
             if ($getComment) {
                 $commentData = unserialize($getComment->getData());
                 //delete the data in the comment confirm table we don't need it anymore
                 Shopware()->Models()->remove($getComment);
                 Shopware()->Models()->flush();
                 $this->sSaveComment($commentData, $blogArticleId);
                 $this->View()->sAction = $this->Request()->getActionName();
                 return $this->forward('detail');
             }
         }
         //validation
         if (empty($this->Request()->name)) {
             $sErrorFlag['name'] = true;
         }
         if (empty($this->Request()->headline)) {
             $sErrorFlag['headline'] = true;
         }
         if (empty($this->Request()->comment)) {
             $sErrorFlag['comment'] = true;
         }
         if (!empty(Shopware()->Config()->CaptchaColor)) {
             $captcha = str_replace(' ', '', strtolower($this->Request()->sCaptcha));
             $rand = $this->Request()->getPost('sRand');
             if (empty($rand) || $captcha != substr(md5($rand), 0, 5)) {
                 $sErrorFlag['sCaptcha'] = true;
             }
         }
         $validator = new Zend_Validate_EmailAddress();
         $validator->getHostnameValidator()->setValidateTld(false);
         if (!empty(Shopware()->Config()->sOPTINVOTE) && (empty($this->Request()->eMail) || !$validator->isValid($this->Request()->eMail))) {
             $sErrorFlag['eMail'] = true;
         }
         if (empty($sErrorFlag)) {
             if (!empty(Shopware()->Config()->sOPTINVOTE) && empty(Shopware()->Session()->sUserId)) {
                 $hash = md5(uniqid(rand()));
                 //save comment confirm for the optin
                 $blogCommentModel = new \Shopware\Models\CommentConfirm\CommentConfirm();
                 $blogCommentModel->setCreationDate(new DateTime("now"));
                 $blogCommentModel->setHash($hash);
                 $blogCommentModel->setData(serialize($this->Request()->getPost()));
                 Shopware()->Models()->persist($blogCommentModel);
                 Shopware()->Models()->flush();
                 $link = $this->Front()->Router()->assemble(array('sViewport' => 'blog', 'action' => 'rating', 'blogArticle' => $blogArticleId, 'sConfirmation' => $hash));
                 $context = array('sConfirmLink' => $link, 'sArticle' => array('title' => $blogArticleData["title"]));
                 $mail = Shopware()->TemplateMail()->createMail('sOPTINVOTE', $context);
                 $mail->addTo($this->Request()->getParam('eMail'));
                 $mail->Send();
             } else {
                 //save comment
                 $commentData = $this->Request()->getPost();
                 $this->sSaveComment($commentData, $blogArticleId);
             }
             $this->View()->sAction = $this->Request()->getActionName();
         } else {
             $this->View()->sFormData = Shopware()->System()->_POST->toArray();
             $this->View()->sErrorFlag = $sErrorFlag;
         }
     }
     $this->forward('detail');
 }
Example #13
0
 /**
  * Private helper method for sValidateStep1
  * Validates email data
  *
  * @param $edit
  * @param $postData
  * @param $sErrorMessages
  * @param $sErrorFlag
  * @return array Error data
  */
 private function validateStep1Email($edit, &$postData, &$sErrorMessages, &$sErrorFlag)
 {
     // Email is present in post data
     if (isset($postData["emailConfirmation"]) || isset($postData["email"])) {
         $postData["email"] = strtolower(trim($postData["email"]));
         $validator = new Zend_Validate_EmailAddress();
         $validator->getHostnameValidator()->setValidateTld(false);
         if (empty($postData["email"]) || !$validator->isValid($postData["email"])) {
             $sErrorFlag["email"] = true;
             $sErrorMessages[] = $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('MailFailure', 'Please enter a valid mail address');
         }
         // Check email confirmation if needed
         if (isset($postData["emailConfirmation"])) {
             $postData["emailConfirmation"] = strtolower(trim($postData["emailConfirmation"]));
             if ($postData["email"] != $postData["emailConfirmation"]) {
                 $sErrorFlag["emailConfirmation"] = true;
                 $sErrorMessages[] = $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('MailFailureNotEqual', 'The mail addresses entered are not equal');
             }
         }
     } elseif ($edit && empty($postData["email"])) {
         $userEmail = $this->session->offsetGet('sUserMail');
         if ($userEmail) {
             $this->front->Request()->setPost('email', $userEmail);
         }
         $postData["email"] = $userEmail;
     }
 }