/**
     * @group ZF-7490
     */
    public function testSettingHostnameMessagesThroughEmailValidator()
    {
        $translations = array(
            'hostnameIpAddressNotAllowed' => 'hostnameIpAddressNotAllowed translation',
            'hostnameUnknownTld' => 'hostnameUnknownTld translation',
            'hostnameDashCharacter' => 'hostnameDashCharacter translation',
            'hostnameInvalidHostnameSchema' => 'hostnameInvalidHostnameSchema translation',
            'hostnameUndecipherableTld' => 'hostnameUndecipherableTld translation',
            'hostnameInvalidHostname' => 'hostnameInvalidHostname translation',
            'hostnameInvalidLocalName' => 'hostnameInvalidLocalName translation',
            'hostnameLocalNameNotAllowed' => 'hostnameLocalNameNotAllowed translation',
        );

        $this->_validator->setMessages($translations);
        $this->_validator->isValid('_XX.!!3xx@0.239,512.777');
        $messages = $this->_validator->getMessages();
        $found = false;
        foreach ($messages as $code => $message) {
            if (array_key_exists($code, $translations)) {
                $this->assertEquals($translations[$code], $message);
                $found = true;
                break;
            }
        }

        $this->assertTrue($found);
    }
示例#2
0
 /**
  * Returns an avatar from gravatar's service.
  *
  * @link http://en.gravatar.com/site/implement/images/php/
  * @throws Zend_View_Exception
  *
  * @param string|null $email Valid email adress
  * @param array $options Options
  * 'imgSize' height of img to return
  * 'defaultImg' img to return if email adress has not found
  * 'rating' rating parametr for avatar
  * @param array $attribs Attribs for img tag (title, alt etc.)
  * @param bool $flag Use HTTPS? Default false.
  * @return string
  */
 public function gravatar($email = null, $options = array(), $attribs = array(), $flag = false)
 {
     if ($email === null) {
         return '';
     }
     if (count($options) > 0) {
         if (isset($options['imgSize'])) {
             $this->setImgSize($options['imgSize']);
         }
         if (isset($options['defaultImg'])) {
             $this->setDefaultImg($options['defaultImg']);
         }
         if (isset($options['rating'])) {
             $this->setRating($options['rating']);
         }
     }
     $validatorEmail = new Zend_Validate_EmailAddress();
     $validatorResult = $validatorEmail->isValid($email);
     if ($validatorResult === false) {
         throw new Zend_View_Exception(current($validatorEmail->getMessages()));
     }
     $hashEmail = md5($email);
     $src = $this->getGravatarUrl($flag) . '/' . $hashEmail . '?s=' . $this->getImgSize() . '&d=' . $this->getDefaultImg() . '&r=' . $this->getRating();
     $attribs['src'] = $src;
     $html = '<img' . $this->_htmlAttribs($attribs) . $this->getClosingBracket();
     return $html;
 }
 public function mailAction()
 {
     $error = array();
     $posts = array('First Name' => $_POST['first_name'], 'Last Name' => $_POST['last_name'], 'Email' => $_POST['email'], 'Message' => $_POST['message']);
     $validatorChain = new Zend_Validate();
     $validatorChain->addValidator(new Zend_Validate_NotEmpty());
     $valid_email = new Zend_Validate_EmailAddress();
     if ($valid_email->isValid($posts['Email'])) {
     } else {
         foreach ($valid_email->getMessages() as $message) {
             $error[] = "Email {$message}\n";
         }
     }
     foreach ($posts as $key => $post) {
         if ($validatorChain->isValid($post)) {
         } else {
             foreach ($validatorChain->getMessages() as $message) {
                 $error[] = "{$key} {$message}\n";
             }
         }
     }
     if (count($error) != 0) {
         $this->view->alerts = $error;
     } else {
         $to = '*****@*****.**';
         $subject = 'Email from Illustrated Portland';
         $message = $posts['Message'];
         $headers = "From: {$posts['First Name']} {$posts['Last Name']} <{$posts['Email']}>";
         mail($to, $subject, $message, $headers);
         //$this->view->alerts = array("Thank You! Your message has been sent.");
     }
 }
 protected function _validateEmail($value = null)
 {
     if ($value) {
         $validator = new Zend_Validate_EmailAddress();
         $validator->setMessage(Mage::helper('eav')->__('"%s" invalid type entered.', $value), Zend_Validate_EmailAddress::INVALID);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid email address.', $value), Zend_Validate_EmailAddress::INVALID_FORMAT);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid hostname.', $value), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid hostname.', $value), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid hostname.', $value), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid email address.', $value), Zend_Validate_EmailAddress::DOT_ATOM);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid email address.', $value), Zend_Validate_EmailAddress::QUOTED_STRING);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid email address.', $value), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
         $validator->setMessage(Mage::helper('eav')->__('"%s" exceeds the allowed length.', $value), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
         if (!$validator->isValid($value)) {
             return array_unique($validator->getMessages());
         }
     }
     return;
 }
示例#5
0
 /**
  * Validates an e-mail address
  *
  * @param   string $address Address
  * @throws  Opus_Mail_Exception Thrown if the e-mail address is not valid
  * @return  string              Address
  */
 public static function validateAddress($address)
 {
     $validator = new Zend_Validate_EmailAddress();
     if ($validator->isValid($address) === false) {
         foreach ($validator->getMessages() as $message) {
             throw new Opus_Mail_Exception($message);
         }
     }
     return $address;
 }
 public function sendAction()
 {
     $form = new Form_MessageUsers();
     $formData = $this->_request->getPost();
     $form->populate($formData);
     if (!$form->isValid($formData)) {
         return $this->_redirectFaultyForm($form);
     }
     $cc = $form->getValue('cc');
     $bccArr = array();
     if (trim($cc) != '') {
         $validator = new Zend_Validate_EmailAddress();
         $bccArr = explode(',', $cc);
         for ($i = 0; $i < count($bccArr); $i++) {
             $bccArr[$i] = trim($bccArr[$i]);
             if (!$validator->isValid($bccArr[$i])) {
                 foreach ($validator->getMessages() as $messageId => $message) {
                     $form->cc->addError($this->view->translate('CC field must be a comma-separated list of valid E-mails'));
                     return $this->_redirectFaultyForm($form);
                 }
             }
         }
     }
     $mail = self::getMail($form->getValue('subject'), $this->_getParam('messageType'), $this->_getParam('messageType') == 'plain' ? $form->getValue('bodyPlain') : $form->getValue('bodyHTML'));
     $mail->setSubject($form->getValue('subject'));
     if ($this->_getParam('messageType') == 'plain') {
         $mail->setBodyText($form->getValue('bodyPlain'));
     } else {
         $mail->setBodyHtml($form->getValue('bodyHTML'));
     }
     $users = new Users_Model_Users();
     // here we get the users emails stored in the users table, even if using LDAP, for performance reasons.
     // Do know however, that a user email is synced with the LDAP repository every time he logs in.
     foreach ($users->getUsers() as $user) {
         if ($user->role == Users_Model_User::ROLE_ADMIN) {
             continue;
         }
         $mail->addBcc($user->email);
     }
     foreach ($bccArr as $bcc) {
         $mail->addBcc($bcc);
     }
     try {
         $mail->send();
         $this->_helper->FlashMessenger->addMessage($this->view->translate('Message has been sent'));
     } catch (Zend_Mail_Protocol_Exception $e) {
         $this->_helper->FlashMessenger->addMessage($this->view->translate('There was an error trying to send the message'));
         if ($this->_config->logging->level == Zend_Log::DEBUG) {
             $this->_helper->FlashMessenger->addMessage($e->getMessage());
             return $this->_redirectFaultyForm($form);
         }
     }
     $this->_redirect('');
 }
示例#7
0
 public function validateEmail($email)
 {
     //Check each post variable for blanks or spaces
     $email_validator = new Zend_Validate_EmailAddress();
     if (!$email_validator->isValid($email)) {
         foreach ($email_validator->getMessages() as $error) {
             array_push($this->messages, $error);
         }
     }
     return $this->messages;
 }
示例#8
0
 protected function _validateEmail()
 {
     if ($this->_doctor->getEmail() != '') {
         $val = new Zend_Validate_EmailAddress();
         if ($val->isValid($this->_doctor->getEmail())) {
             return true;
         }
         $msg = Sanmax_MessageStack::getInstance('SxModule_Doctor');
         $msg->addMessage('email', $val->getMessages());
         return false;
     }
 }
 public function emailAction()
 {
     $v = new Zend_Validate_EmailAddress();
     $string = '*****@*****.**';
     if ($v->isValid($string)) {
         echo "{$string} eh email";
     } else {
         echo "{$string} nao eh email";
         $erros = $v->getMessages();
         print_r($erros);
     }
     exit;
 }
示例#10
0
 /**
  * Validates email address
  *
  * @return boolean
  */
 protected function _validateEmail()
 {
     $validator = new Zend_Validate_EmailAddress();
     $msg = Sanmax_MessageStack::getInstance('SxCms_User');
     if (!$validator->isValid($this->_user->getEmail())) {
         $msg->addMessage('email', $validator->getMessages());
     }
     $exclude = array('field' => 'user_id', 'value' => (int) $this->_user->getId());
     $validator = new Zend_Validate_Db_NoRecordExists('User', 'email', $exclude);
     if (!$validator->isValid($this->_user->getEmail())) {
         $msg->addMessage('email', $validator->getMessages(), 'common');
     }
     return false == $msg->getMessages('email');
 }
示例#11
0
 public function emailCheck()
 {
     $email = $this->_data['email'];
     if ($this->_db_user->usernameIsExist($email)) {
         $this->addMessage('email', $this->_t->_('This user is exist.'));
     }
     $validator = new Zend_Validate_EmailAddress();
     if (!$validator->isValid($email)) {
         // email is invalid; print the reasons
         foreach ($validator->getMessages() as $message) {
             $this->addMessage('email', $this->_t->_($message));
         }
     }
 }
 /**
  * Ensures that getMessages() returns expected default value (an empty array)
  *
  * @return void
  */
 public function testGetMessages()
 {
     $this->assertEquals(array(), $this->_validator->getMessages());
 }
示例#13
0
 /**
  * registers a new user
  *
  * @param   array   $regData        json data from registration frontend
  * @param   bool    $_sendMail      send registration mail
  * @return  bool
  * 
  */
 public function registerUser($regData, $_sendMail = true)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' call registerUser with regData: ' . print_r($regData, true));
     }
     // validate unique username
     //@todo     move to frontend later on
     if (!$this->checkUniqueUsername($regData['accountLoginName'])) {
         throw new Exception('Your chosen username already exists!');
     }
     // validate email address
     if (isset($this->_config->emailValidation) && $this->_config->emailValidation == 'zend') {
         // zend email validation isn't working on a 64bit os at the moment (v1.5.0)
         require_once 'Zend/Validate/EmailAddress.php';
         $validator = new Zend_Validate_EmailAddress();
         if ($validator->isValid($regData['accountEmailAddress']) == false) {
             // email is invalid; print the reasons
             $debugMessage = 'Invalid registration email address: ' . $regData['accountEmailAddress'] . '( ';
             foreach ($validator->getMessages() as $message) {
                 $debugMessage .= $message . " ";
             }
             $debugMessage .= ')';
             // throw exception
             throw new Exception('Invalid registration email address: ' . $debugMessage);
         }
     }
     // check invitation
     //@todo     move to frontend later on
     if (isset($this->_config->invitationOnly) && $this->_config->invitationOnly == 1 && !$this->checkInvitation($regData['accountEmailAddress'])) {
         throw new Exception('Invalid registration email address (not invited)!');
     }
     // add more required fields to regData
     // get default values from config if available
     $regData['accountStatus'] = isset($this->_config->accountStatus) ? $this->_config->accountStatus : 'enabled';
     $regData['accountDisplayName'] = $regData['accountFirstName'] . ' ' . $regData['accountLastName'];
     $regData['accountFullName'] = $regData['accountDisplayName'];
     // get groupbyname
     $primaryGroupName = isset($this->_config->accountPrimaryGroup) ? $this->_config->accountPrimaryGroup : 'Users';
     $primaryGroup = Tinebase_Group::getInstance()->getGroupByName($primaryGroupName);
     $regData['accountPrimaryGroup'] = $primaryGroup->getId();
     // add expire date (user has 1 day to click on the activation link)
     if (isset($this->_config->expires) && $this->_config->expires > 0) {
         $regData['accountExpires'] = new Tinebase_DateTime();
         // add 'expires' from config hours
         $timeToAdd = $this->_config->expires . ":00:00";
         TinebaseCore::getLogger()->debug("this account expires in {$timeToAdd} hours ...");
         $regData['accountExpires']->add($this->_config->expires, Tinebase_DateTime::MODIFIER_HOUR);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug("this account never expires.");
         }
         $regData['accountExpires'] = NULL;
     }
     // get model & save user data (account & contact) via the User and Addressbook controllers
     $account = new Tinebase_Model_FullUser($regData);
     Tinebase_User::getInstance()->addUser($account);
     Tinebase_Group::getInstance()->addGroupMember($account->accountPrimaryGroup, $account);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' saved user ' . $regData['accountLoginName']);
     }
     // generate password and save it
     $regData['password'] = $this->generatePassword();
     Tinebase_User::getInstance()->setPassword($regData['accountLoginName'], $regData['password'], $regData['password']);
     // create hash from username
     $regData['accountLoginNameHash'] = md5($regData['accountLoginName']);
     // save in registrations table
     $registration = new Tinebase_Model_Registration(array("login_name" => $regData['accountLoginName'], "login_hash" => $regData['accountLoginNameHash'], "email" => $regData['accountEmailAddress']));
     $registration = $this->addRegistration($registration);
     // send mail?
     if ($_sendMail) {
         $result = $this->sendRegistrationMail($regData, $registration);
     } else {
         $result = true;
     }
     return $result;
 }
示例#14
0
    function recAction()
    {
        Zend_Loader::loadClass('Zend_Filter_StripTags');
        Zend_Loader::loadClass('Zend_Mail');
        Zend_Loader::loadClass('Zend_Validate_EmailAddress');
        $filter = new Zend_Filter_StripTags();
        $email = trim($filter->filter($this->_request->getPost('rec-email')));
        $warnings = new Zend_Session_Namespace();
        $error_msg = '';
        $mail_val = new Zend_Validate_EmailAddress();
        if ($email == '') {
            $error_msg .= '<p>Enter your email.</p>';
        } else {
            if (!$mail_val->isValid($email)) {
                foreach ($mail_val->getMessages() as $message) {
                    $error_msg .= '<p>' . $message . '</p>';
                }
            }
        }
        $data = new Users();
        $query = 'email = "' . $email . '"';
        $data_row = $data->fetchRow($query);
        if (!count($data_row)) {
            $error_msg .= '<p>Can`t find user with such email.</p>';
        } else {
            $salt = $data_row['salt'];
        }
        if ($error_msg != '') {
            $warnings->error = $error_msg;
            $warnings->status = '';
            $this->_redirect('/register/recovery');
        } else {
            $ranges = array(range('a', 'z'), range('A', 'Z'), range(1, 9));
            $length = 8;
            $pass = '';
            for ($i = 0; $i < $length; $i++) {
                $rkey = array_rand($ranges);
                $vkey = array_rand($ranges[$rkey]);
                $pass .= $ranges[$rkey][$vkey];
            }
            $hash = sha1($pass . $salt);
            $user_update = new Users();
            $where = 'email = "' . $email . '"';
            $dates = array('password' => $hash);
            $user_update->update($dates, $where);
            $mail = new Zend_Mail();
            $url = $this->getRequest()->getServer('HTTP_HOST');
            $mail->setBodyHtml('<p>Your new password.</p>
								<p>Password: '******'</p>
								');
            $mail->setFrom('*****@*****.**', 'Administrator');
            $mail->addTo($email, $data_row['login']);
            $mail->setSubject('Test password recovery');
            $mail->send();
            $warnings->error = '<p>Password was sent to ' . $email . '.</p>';
            $warnings->status = ' reg_ok';
            $this->_redirect('/register/recovery');
            return;
        }
    }
示例#15
0
文件: Base.php 项目: rukzuk/rukzuk
 /**
  * @param  string $email
  * @param  string  $field
  * @return boolean
  */
 protected function validateEmail($email, $field = 'email')
 {
     $emailValidator = new EmailValidator(array('hostname' => new \Zend_Validate_Hostname(array('tld' => false))));
     $emailValidator->setMessage('Ungültiger Typ. String erwartet', EmailValidator::INVALID);
     $emailValidator->setMessage("'%value%' ist keine gültige Email nach dem Format name@hostname", EmailValidator::INVALID_FORMAT);
     $emailValidator->setMessage("'%hostname%' ist kein gültiger Hostname für die Email '%value%'", EmailValidator::INVALID_HOSTNAME);
     $emailValidator->setMessage("'%value%' ist länger als die zulässige Länge", EmailValidator::LENGTH_EXCEEDED);
     if (!$emailValidator->isValid($email)) {
         $messages = array_values($emailValidator->getMessages());
         $this->addError(new Error($field, $email, $messages));
         return false;
     }
     return true;
 }
示例#16
0
 /**
  * Validate the email
  *
  * @return boolean
  */
 protected function _validateEmail()
 {
     $author = $this->comment->getCommenter();
     $validator = new Zend_Validate_EmailAddress();
     if (!$validator->isValid($author->getEmail())) {
         $this->errors['email'] = $validator->getMessages();
         return false;
     }
     return true;
 }
示例#17
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = Mage::helper('customer')->__($this->getAttribute()->getStoreLabel());
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 $this->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 $this->__("Invalid type given. String expected")
                 $this->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 $this->__("'%value%' does not match the expected structure for a DNS hostname")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 $this->__("'%value%' does not appear to be a valid local network name")
                 $this->__("'%value%' does not appear to be a valid URI hostname")
                 $this->__("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 $this->__("'%value%' appears to be a local network name but local network names are not allowed")
                 $this->__("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
     return true;
 }
示例#18
0
 /**
  * Validates email address
  *
  * @return bool
  */
 protected function _validateEmail()
 {
     if (!strlen($this->_job->getEmail())) {
         return true;
     }
     $validator = new Zend_Validate_EmailAddress();
     $validator->setOptions(array('domain' => false, 'mx' => false));
     if ($validator->isValid($this->_job->getEmail())) {
         return true;
     }
     $msg = Sanmax_MessageStack::getInstance('SxCms_Job');
     $msg->addMessage('email', $validator->getMessages(), 'location');
     return false;
 }
示例#19
0
 public function sendAction()
 {
     $message = $status = $invalid_mails = '';
     $form = new forms_MailForm();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $tr = new Zend_Mail_Transport_Sendmail('*****@*****.**');
             Zend_Mail::setDefaultTransport($tr);
             $params = $this->_getAllParams();
             $exclude = array('controller', 'action', 'module', 'subject', 'recipients');
             $subject = $this->_getParam('subject', 'Athlon mailer test mail');
             $recipients = $this->_getParam('recipients', '');
             $mail_addresses = array_map("trim", explode("\n", $recipients));
             foreach ($params as $name => $value) {
                 if (!in_array($name, $exclude)) {
                     $filename = ROOT_DIR . '/public/files/uploaded/' . $value;
                     $handle = fopen($filename, 'r');
                     $content = fread($handle, filesize($filename));
                     fclose($handle);
                     foreach ($mail_addresses as $recipient) {
                         $validator = new Zend_Validate_EmailAddress();
                         if ($validator->isValid($recipient)) {
                             $mail = new Zend_Mail();
                             $mail->setBodyHtml($content);
                             $mail->setFrom('*****@*****.**');
                             $mail->addTo($recipient);
                             $mail->setSubject($subject);
                             $mail->send();
                         } else {
                             foreach ($validator->getMessages() as $messageId => $message) {
                                 $invalid_mails .= '<strong>' . $messageId . ': </strong>' . $message . '<br />';
                             }
                         }
                     }
                 }
             }
             $status = 'Success';
             $message = '';
             if (strlen($invalid_mails) > 0) {
                 $status = 'Error';
                 $message .= '<div class=\'errorExplanation\' id=\'errorExplanation\'><h2>There were some errors during the process</h2><p>Please review them below</p><p>' . $invalid_mails . '</p></div>';
             } else {
                 $message = 'Done sending emails to ' . sizeof($mail_addresses) . ' recipients';
             }
         } else {
             $status = 'Error';
             foreach ($form->getMessages() as $element => $errorMessages) {
                 foreach ($errorMessages as $messageId => $message) {
                     $invalid_mails .= '<strong>' . $element . ' ' . $messageId . ': </strong>' . $message . '<br />';
                 }
             }
             $message = '<div class=\'errorExplanation\' id=\'errorExplanation\'><h2>There were some errors during the process</h2><p>Please review them below</p><p>' . $invalid_mails . '</p></div>';
         }
         $this->view->status = $status;
         $this->view->message = $message;
     } else {
         $redirector = $this->_helper->getHelper('Redirector');
         //setGotoSimple("action","controller");
         $redirector->setCode(303)->setExit(false)->setGotoSimple("index", "index");
         $redirector->redirectAndExit();
     }
 }
示例#20
0
 public function test上書きしたメッセージがエラー時に表示する()
 {
     $instance = new Gene_Translate(GENE_APP_PATH);
     $path = GENE_TEST_ROOT . '/var/resources/languages/ja';
     $translate = $instance->getValidateTranslate();
     $result = $instance->mergeTranslate($translate, $path);
     $key = key(self::$_data);
     Zend_Validate_Abstract::setDefaultTranslator($result);
     $validator = new Zend_Validate_EmailAddress();
     $validator->isValid('example@examle.c');
     $messages = $validator->getMessages();
     $this->assertSame($messages[Zend_Validate_EmailAddress::INVALID_HOSTNAME], self::$_data[$key]);
 }
 /**
  * Validate email
  *
  * @param string $value
  * @return string
  */
 protected function _validateEmail($value)
 {
     $label = Mage::helper('enterprise_rma')->getContactEmailLabel();
     $validator = new Zend_Validate_EmailAddress();
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
     if (!$validator->isValid($value)) {
         return array_unique($validator->getMessages());
     }
     return true;
 }
示例#22
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $format = Mage::app()->getLocale()->getDateFormat(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator = new Zend_Validate_Date($format);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 break;
         }
     }
     return true;
 }
示例#23
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return array|true
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidationRules();
     $inputValidation = ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation');
     if (!is_null($inputValidation)) {
         switch ($inputValidation) {
             case 'alphanumeric':
                 $validator = new \Zend_Validate_Alnum(true);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(__('"%1" contains non-alphabetic or non-numeric characters.', $label), \Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new \Zend_Validate_Digits();
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Digits::INVALID);
                 $validator->setMessage(__('"%1" contains non-numeric characters.', $label), \Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new \Zend_Validate_Alpha(true);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(__('"%1" contains non-alphabetic characters.', $label), \Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 __("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 __("Invalid type given. String expected")
                 __("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 __("'%value%' does not match the expected structure for a DNS hostname")
                 __("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 __("'%value%' does not appear to be a valid local network name")
                 __("'%value%' does not appear to be a valid URI hostname")
                 __("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 __("'%value%' appears to be a local network name but local network names are not allowed")
                 __("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 __("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new \Zend_Validate_EmailAddress();
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(__('"%1" uses too many characters.', $label), \Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(__("'%value%' looks like an IP address, which is not an acceptable format."), \Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match the TLD against known list."), \Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but contains a dash in an invalid position."), \Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match it against the hostname schema for TLD '%tld%'."), \Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but cannot extract TLD part."), \Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(__("'%value%' does not look like a valid local network name."), \Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(__("'%value%' looks like a local network name, which is not an acceptable format."), \Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(__("'%value%' appears to be a DNS hostname, but the given punycode notation cannot be decoded."), \Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return [__('"%1" is not a valid URL.', $label)];
                 }
                 $validator = new \Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return [__('"%1" is not a valid URL.', $label)];
                 }
                 break;
             case 'date':
                 $validator = new \Zend_Validate_Date(\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Date::INVALID);
                 $validator->setMessage(__('"%1" is not a valid date.', $label), \Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(__('"%1" does not fit the entered date format.', $label), \Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
     return true;
 }
示例#24
0
 /**
  * Set mail options method
  *
  * @param string $body    Body string
  * @param array $from     Sender emails
  * @param array $addTo    Recipients emails
  * @param string $subject Subject of the mail
  */
 public static function setMailOptions($body, $from, $addTo, $subject)
 {
     if (self::$_mail == null) {
         self::_setMailObj();
     }
     // Validation Classes:
     $validMail = new Zend_Validate_EmailAddress();
     $validString = new Zend_Validate_StringLength(8);
     // Validate email body
     if ($validString->isValid($body)) {
         self::$_mail->setBodyText($body);
     } else {
         throw new Exception(implode($validString->getMessages(), '\\n'));
     }
     // Validate sender email
     if ($validMail->isValid($from)) {
         $emailFrom = $from;
     } else {
         throw new Exception(implode($validMail->getMessages(), '\\n'));
     }
     self::$_mail->setFrom($emailFrom);
     // Validate recipient email
     if ($validMail->isValid($addTo)) {
         $emailTo = $addTo;
     } else {
         throw new Exception(implode($validMail->getMessages(), '\\n'));
     }
     self::$_mail->addTo($emailTo);
     // Validte subject
     if ($validString->isValid($subject)) {
         self::$_mail->setSubject($subject);
     } else {
         throw new Exception(implode($validString->getMessages(), '\\n'));
     }
 }