public function __construct()
 {
     $validatorEmail = new EmailAddress();
     $validatorEmail->setOptions(array('domain' => FALSE));
     $this->add(array('name' => 'email', 'filters' => array(array('name' => 'StringTrim'), array('name' => 'StripTags')), 'validators' => array($validatorEmail, array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Digite corretamente o seu e-mail!'))))));
     $this->add(array('name' => 'senha', 'required' => true, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'StripTags'))));
 }
Exemple #2
0
 /**
  * Testing setOptions
  */
 public function testSetOptions()
 {
     $this->validator->setOptions(array('messages' => array(EmailAddress::INVALID => 'TestMessage')));
     $messages = $this->validator->getMessageTemplates();
     $this->assertEquals('TestMessage', $messages[EmailAddress::INVALID]);
     $oldHostname = $this->validator->getHostnameValidator();
     $this->validator->setOptions(array('hostnameValidator' => new Hostname(Hostname::ALLOW_ALL)));
     $hostname = $this->validator->getHostnameValidator();
     $this->assertNotEquals($oldHostname, $hostname);
 }
Exemple #3
0
 /**
  * @param $data
  * @param bool $reservationId
  * @return array
  */
 public function validateAndCheckDiscountData($data, $reservationId = false)
 {
     $result = ['valid' => false, 'message' => ''];
     try {
         if ($reservationId) {
             /**
              * @var \DDD\Dao\Booking\Booking $reservationDao
              */
             $reservationDao = $this->getServiceLocator()->get('dao_booking_booking');
             $reservationData = $reservationDao->getDataForDiscountValidationById($reservationId);
             $data = ['email' => $reservationData->getGuestEmail(), 'aff_id' => $reservationData->getPartnerId()];
         }
         $visitor = new Container('visitor');
         if (!isset($data['aff_id']) && !is_null($visitor->partnerId) && (int) $visitor->partnerId) {
             $data['aff_id'] = (int) $visitor->partnerId;
         }
         $emailValidator = new EmailAddress();
         $emailValidator->setOptions(['domain' => true]);
         // validate Email for ginosiks
         if (isset($data['aff_id']) && $data['aff_id'] == self::SECRET_DISCOUNT_AFFILIATE_ID) {
             if (!isset($data['email']) || empty($data['email'])) {
                 $result['message'] .= "Email field is not submitted.\n";
             } elseif (!$emailValidator->isValid($data['email'])) {
                 $result['message'] .= "Email not valid.\n";
             } else {
                 /**
                  * @var UserManager $userManager
                  */
                 $userManager = $this->getServiceLocator()->get('dao_user_user_manager');
                 $userRow = $userManager->getUserIdByEmailAddress($data['email']);
                 // validate User
                 if (!$userRow['id']) {
                     $result['message'] .= "Email does not match the Ginosi User.\n";
                 } elseif ($userRow['system'] != 0 || $userRow['disabled'] != 0) {
                     $result['message'] .= "User disabled or system.\n";
                 } else {
                     $result['email'] = strtolower($data['email']);
                 }
             }
         }
         // validate Affiliate Id
         if (!isset($data['aff_id']) || !is_numeric($data['aff_id'])) {
             $result['message'] .= "Affiliate Id field is not submitted.\n";
         } else {
             $result['aff_id'] = (int) $data['aff_id'];
         }
         // get Affiliate Discount Value
         if (isset($result['aff_id'])) {
             /**
              * @var PartnersDAO $partnerDao
              */
             $partnerDao = $this->getServiceLocator()->get('dao_partners_partners');
             $partnerData = $partnerDao->getPartnerNameAndDiscountById($result['aff_id']);
             // check Affiliate Discount Value
             if (empty($partnerData['discount']) && $partnerData['discount'] <= 0) {
                 $result['message'] .= "Affiliate does not have discounts.\n";
             } else {
                 $result['discount_value'] = $partnerData['discount'];
                 $result['partner_name'] = $partnerData['partner_name'];
             }
         }
         // final judgment
         if (empty($result['message'])) {
             $result['valid'] = true;
             unset($result['message']);
         }
     } catch (\Exception $e) {
         $this->gr2logException($e, 'Cannot validate and check reservation discount data', $data);
     }
     return $result;
 }
Exemple #4
0
 public function getEmailValidator()
 {
     if ($this->emailValidator === NULL) {
         $validator = new EmailAddress();
         $validator->setOptions($this->getEmailConfig())->setMessages(array(EmailAddress::DOT_ATOM => $this->getErrorMessage('EMAILADDRESS::DOT_ATOM'), EmailAddress::INVALID => $this->getErrorMessage('EMAILADDRESS::INVALID'), EmailAddress::INVALID_FORMAT => $this->getErrorMessage('EMAILADDRESS::INVALID_FORMAT'), EmailAddress::INVALID_HOSTNAME => $this->getErrorMessage('EMAILADDRESS::INVALID_HOSTNAME'), EmailAddress::INVALID_LOCAL_PART => $this->getErrorMessage('EMAILADDRESS::INVALID_LOCAL_PART'), EmailAddress::INVALID_MX_RECORD => $this->getErrorMessage('EMAILADDRESS::INVALID_MX_RECORD'), EmailAddress::INVALID_SEGMENT => $this->getErrorMessage('EMAILADDRESS::INVALID_SEGMENT'), EmailAddress::LENGTH_EXCEEDED => $this->getErrorMessage('EMAILADDRESS::LENGTH_EXCEEDED'), EmailAddress::QUOTED_STRING => $this->getErrorMessage('EMAILADDRESS::QUOTED_STRING')));
         $this->setEmailValidator($validator);
     }
     return $this->emailValidator;
 }