public function loginAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $email = $request->getPost('user-email', false);
         $password = $request->getPost('user-password', false);
         $empty_obj = new NotEmpty();
         if (!$empty_obj->isValid($email) || !$email) {
             throw new \RuntimeException("El usuario no es válido");
         }
         if (!$empty_obj->isValid($password) || !$password) {
             throw new \RuntimeException("La contraseña no es válida");
         }
         $password = Encrypt::encrypt(trim($password), trim($email));
         $email = md5(trim($email));
         $user_obj = $this->em->getRepository('Application\\Entity\\WebsiteTbSecurityUser')->findOneBySusvLogin($email);
         if (!$empty_obj->isValid($user_obj)) {
             throw new \RuntimeException("El ussuario no es válido");
         }
         if ($user_obj->getSusvPassword() !== $password) {
             throw new \RuntimeException("La contraseña no es válida");
         }
         $user = array('userId' => $user_obj->getSusi()->getSusiId(), 'userEntity' => $user_obj->getSeni()->getSeniId(), 'userName' => $user_obj->getSusi()->getSudvName(), 'userEmail' => $user_obj->getSusvLoginname());
         $this->getServiceLocator()->get('AuthService')->setStorage($this->getSessionStorage());
         $this->getServiceLocator()->get('AuthService')->getStorage()->write($user);
         return $this->redirect()->toRoute('dashboard');
     }
 }
Example #2
0
 /**
  * Add access token to Request Parameters
  *
  * @throws Exception\InvalidArgumentException
  */
 public function preSend(Event $e)
 {
     $validator = new NotEmpty();
     if (!isset($this->options['tokenOrLogin']) || !$validator->isValid($this->options['tokenOrLogin'])) {
         throw new Exception\InvalidArgumentException('You need to set OAuth token!');
     }
     $request = $e->getTarget();
     $query = $request->getQuery();
     $query->set('access_token', $this->options['tokenOrLogin']);
 }
Example #3
0
 /**
  * Add Client Id and Client Secret to Request Parameters
  *
  * @throws Exception\InvalidArgumentException
  */
 public function preSend(Event $e)
 {
     $validator = new NotEmpty();
     if (!array_key_exists('client_id', $this->options) || !$validator->isValid($this->options['client_id'])) {
         throw new Exception\InvalidArgumentException('You need to set client_id!');
     }
     $request = $e->getTarget();
     $query = $request->getQuery();
     $query->set('client_id', $this->options['client_id']);
 }
Example #4
0
 /**
  * @param string $message
  * @return NotEmpty
  */
 public static function notEmptyValidator($message = null)
 {
     $validator = new NotEmpty();
     $validator->setOptions(['break_chain_on_failure' => true]);
     if ($message) {
         $validator->setMessage($message);
     } else {
         $validator->setMessage("Input masih kosong.");
     }
     return $validator;
 }
Example #5
0
 /**
  * Add Authorization Token to Header
  *
  * @throws Exception\InvalidArgumentException
  */
 public function preSend(Event $e)
 {
     $validator = new NotEmpty();
     if (!isset($this->options['tokenOrLogin']) || !$validator->isValid($this->options['tokenOrLogin'])) {
         throw new Exception\InvalidArgumentException('You need to set OAuth token!');
     }
     $request = $e->getTarget();
     $headers = $request->getHeaders();
     $params = array('Authorization' => 'token ' . $this->options['tokenOrLogin']);
     $headers->addHeaders($params);
 }
Example #6
0
 /**
  *  Add Basic Authnentication to Header
  *
  * @throws Exception\InvalidArgumentException
  */
 public function preSend(Event $e)
 {
     $validator = new NotEmpty();
     if (!isset($this->options['tokenOrLogin'], $this->options['password']) || !$validator->isValid($this->options['tokenOrLogin']) || !$validator->isValid($this->options['password'])) {
         throw new Exception\InvalidArgumentException('You need to set username with password!');
     }
     $request = $e->getTarget();
     $headers = $request->getHeaders();
     $params = array('Authorization' => 'Basic ' . base64_encode($this->options['tokenOrLogin'] . ':' . $this->options['password']));
     $headers->addHeaders($params);
 }
Example #7
0
 /**
  * Add Client Id and Client Secret to Request Parameters
  *
  * @throws Exception\InvalidArgumentException
  */
 public function preSend(Event $e)
 {
     $validator = new NotEmpty();
     if (!isset($this->options['tokenOrLogin'], $this->options['password']) || !$validator->isValid($this->options['tokenOrLogin']) || !$validator->isValid($this->options['password'])) {
         throw new Exception\InvalidArgumentException('You need to set client_id and client_secret!');
     }
     $request = $e->getTarget();
     $query = $request->getQuery();
     $query->set('client_id', $this->options['tokenOrLogin']);
     $query->set('client_secret', $this->options['password']);
 }
Example #8
0
 public function getFormAction()
 {
     $aRequest = $this->getRequest();
     $aPost = $aRequest->getPost();
     $sMail = $aPost['email'];
     $sSubject = $aPost['subject'];
     $validator = new Validator\EmailAddress();
     $validMessage = new Validator\NotEmpty();
     if (!$this->_validCaptcha($aPost['g-recaptcha-response'])) {
         return $this->redirect()->toRoute('contact');
     }
     if (!$validator->isValid($sMail)) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("L'adresse e-mail renseignée n'est pas valide."), 'error');
         return $this->redirect()->toRoute('contact');
     }
     if (!$validMessage->isValid($aPost['message'])) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Votre message est vide."), 'error');
         return $this->redirect()->toRoute('contact');
     }
     $oViewModel = new ViewModel(array('post' => $aPost));
     $oViewModel->setTemplate('accueil/contact/mail_contact');
     $oViewModel->setTerminal(true);
     $sm = $this->getServiceLocator();
     $html = new MimePart(nl2br($sm->get('ViewRenderer')->render($oViewModel)));
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $oMail = new Message();
     $oMail->setBody($body);
     $oMail->setEncoding('UTF-8');
     $oMail->setFrom('*****@*****.**');
     $oMail->addTo('*****@*****.**');
     // $oMail->addCc('*****@*****.**');
     $oMail->setSubject($sSubject);
     $oSmtpOptions = new \Zend\Mail\Transport\SmtpOptions();
     $oSmtpOptions->setHost($this->_getServConfig()['mail']['auth'])->setConnectionClass('login')->setName($this->_getServConfig()['mail']['namelocal'])->setConnectionConfig(array('username' => $this->_getServConfig()['mail']['username'], 'password' => $this->_getServConfig()['mail']['password'], 'ssl' => $this->_getServConfig()['mail']['ssl']));
     $oSend = new \Zend\Mail\Transport\Smtp($oSmtpOptions);
     $bSent = true;
     try {
         $oSend->send($oMail);
     } catch (\Zend\Mail\Transport\Exception\ExceptionInterface $e) {
         $bSent = false;
         $this->flashMessenger()->addMessage($e->getMessage(), 'error');
     }
     if ($bSent) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Votre message a été envoyé."), 'success');
         $this->_getLogService()->log(LogService::NOTICE, "Email de {$sMail}", LogService::USER);
     } else {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Votre message n'a pu être envoyé."), 'error');
         $this->_getLogService()->log(LogService::ERR, "Erreur d'envoie de mail à {$sMail}", LogService::USER);
     }
     return $this->redirect()->toRoute('contact');
 }
Example #9
0
 /**
  * Checks that the validation value matches the expected validity
  *
  * @param mixed $value Value to validate
  * @param bool  $valid Expected validity
  *
  * @return void
  */
 protected function checkValidationValue($value, $valid)
 {
     $isValid = $this->validator->isValid($value);
     if ($valid) {
         $this->assertTrue($isValid);
     } else {
         $this->assertFalse($isValid);
     }
 }
 /**
  * @param string        $value
  * @param string[]|null $context
  */
 public function isValid($value, $context = null)
 {
     if (!is_array($context) || !isset($context['countryCode'])) {
         $this->error(static::MISSING_COUNTRY_CODE);
         return false;
     }
     $countryCode = trim($context['countryCode']);
     $fields = $this->addressService->getFieldsForCountry($countryCode);
     if (!isset($fields[$this->fieldName]) || !$fields[$this->fieldName]) {
         return true;
     }
     return parent::isValid($value);
 }
Example #11
0
 /**
  * @return bool
  */
 public function validate()
 {
     $this->validateFields($this->getFieldsForValidation(), $this->getData());
     $data = $this->getData();
     $notEmpty = new NotEmpty();
     $stringLength = new StringLength();
     $digits = new Digits();
     if (!$notEmpty->isValid($data['name'])) {
         $this->addError('Name', Validator::ERROR_NOT_EMPTY);
     }
     if (!$stringLength->isValid($data['name'])) {
         $this->addError('Name', Validator::ERROR_NOT_STRING);
     }
     if (!$notEmpty->isValid($data['amount'])) {
         $this->addError('Amount', Validator::ERROR_NOT_EMPTY);
     }
     if (!is_float($data['amount'])) {
         $this->addError('Amount', Validator::ERROR_NOT_AMOUNT);
     }
     if (!$notEmpty->isValid($data['quantity'])) {
         $this->addError('Quantity', Validator::ERROR_NOT_EMPTY);
     }
     if (!$digits->isValid($data['quantity'])) {
         $this->addError('Quantity', Validator::ERROR_NOT_INTEGER);
     }
     if (!$notEmpty->isValid($data['uniqueId'])) {
         $this->addError('uniqueId', Validator::ERROR_NOT_EMPTY);
     }
     if (!$stringLength->isValid($data['uniqueId'])) {
         $this->addError('uniqueId', Validator::ERROR_NOT_STRING);
     }
     // Optional field: Currency
     if (isset($data['currency'])) {
         if (!$stringLength->isValid($data['currency'])) {
             $this->addError('currency', Validator::ERROR_NOT_STRING);
         }
     }
     return $this->confirmValidation();
 }
Example #12
0
 public function isValid($value)
 {
     $type = $this->getType();
     // allow zero float
     if ($type >= self::FLOAT && $value == 0.0) {
         return true;
     }
     // allow integer zero
     if ($type >= self::INTEGER && $value == 0) {
         return true;
     }
     // go on with zend validator
     return parent::isValid($value);
 }
 public function __construct(EntityManager $em)
 {
     $input = new Input('prenom');
     $validator = new NotEmpty();
     $validator->setMessage('Le prénom est obligatoire', NotEmpty::IS_EMPTY);
     $input->getValidatorChain()->attach($validator);
     $filter = new StringTrim();
     $input->getFilterChain()->attach($filter);
     $this->add($input);
     $input = new Input('email');
     $input->setRequired(false);
     // TODO ne fonctionne pas pour l'UPDATE
     $validator = new NoObjectExists(array('object_repository' => $em->getRepository('AddressBook\\Entity\\Contact'), 'fields' => 'email'));
     $validator->setMessage("Un utilisateur utilise déjà cet email", NoObjectExists::ERROR_OBJECT_FOUND);
     $input->getValidatorChain()->attach($validator);
     if (class_exists('Zend\\Filter\\ToNull')) {
         $filter = new \Zend\Filter\ToNull();
     } else {
         if (class_exists('Zend\\Filter\\Null')) {
             $filter = new \Zend\Filter\Null();
         }
     }
     $input->getFilterChain()->attach($filter);
     $this->add($input);
     $input = new Input('societe');
     $input->setRequired(false);
     if (class_exists('Zend\\Filter\\ToNull')) {
         $filter = new \Zend\Filter\ToNull();
     } else {
         if (class_exists('Zend\\Filter\\Null')) {
             $filter = new \Zend\Filter\Null();
         }
     }
     $input->getFilterChain()->attach($filter);
     $this->add($input);
 }
 public function isValid($sValue, $mContext = null)
 {
     $this->setValue($sValue);
     $sElementName = $this->getOption('element_name');
     $oNotEmptyValidator = new NotEmptyValidator();
     $bIsStudent = (bool) $mContext['is_student'];
     $bIsEmployee = (bool) $mContext['is_employee'];
     $bIsBorrower = (bool) $mContext['is_borrower'];
     if ($sElementName === 'student_organization_key' && $bIsStudent && !$oNotEmptyValidator->isValid($this->getValue())) {
         $this->error(self::IS_EMPTY);
         return false;
     } else {
         if ($sElementName === 'employee_organization_key' && $bIsEmployee && !$oNotEmptyValidator->isValid($this->getValue())) {
             $this->error(self::IS_EMPTY);
             return false;
         } else {
             if ($sElementName === 'btype' && ($bIsEmployee || $bIsStudent) && !$oNotEmptyValidator->isValid($this->getValue())) {
                 $this->error(self::IS_EMPTY);
                 return false;
             }
         }
     }
     return true;
 }
Example #15
0
 /**
  * @ZF-8767
  *
  * @return void
  */
 public function testZF8767()
 {
     $valid = new Validator\NotEmpty(Validator\NotEmpty::STRING);
     $this->assertFalse($valid->isValid(''));
     $messages = $valid->getMessages();
     $this->assertTrue(array_key_exists('isEmpty', $messages));
     $this->assertContains("can't be empty", $messages['isEmpty']);
 }
Example #16
0
 /**
  * @group ZF-11267
  * If we pass in a validator instance that has a preset custom message, this
  * message should be used.
  */
 function testIfCustomMessagesOnValidatorInstancesCanBeUsed()
 {
     // test with a Digits validator
     $data = array('field1' => 'invalid data');
     $customMessage = 'Hey, that\'s not a Digit!!!';
     $validator = new Validator\Digits();
     $validator->setMessage($customMessage, 'notDigits');
     $this->assertFalse($validator->isValid('foo'), 'standalone validator thinks \'foo\' is a valid digit');
     $messages = $validator->getMessages();
     $this->assertSame($messages['notDigits'], $customMessage, 'stanalone validator does not have custom message');
     $validators = array('field1' => $validator);
     $input = new InputFilter(null, $validators, $data);
     $this->assertFalse($input->isValid(), 'invalid input is valid');
     $messages = $input->getMessages();
     $this->assertSame($messages['field1']['notDigits'], $customMessage, 'The custom message is not used');
     // test with a NotEmpty validator
     $data = array('field1' => '');
     $customMessage = 'You should really supply a value...';
     $validator = new Validator\NotEmpty();
     $validator->setMessage($customMessage, 'isEmpty');
     $this->assertFalse($validator->isValid(''), 'standalone validator thinks \'\' is not empty');
     $messages = $validator->getMessages();
     $this->assertSame($messages['isEmpty'], $customMessage, 'stanalone NotEmpty validator does not have custom message');
     $validators = array('field1' => $validator);
     $input = new InputFilter(null, $validators, $data);
     $this->assertFalse($input->isValid(), 'invalid input is valid');
     $messages = $input->getMessages();
     $this->assertSame($messages['field1']['isEmpty'], $customMessage, 'For the NotEmpty validator the custom message is not used');
 }
Example #17
0
 /**
  * @return void
  */
 public function testStringObjects()
 {
     $valid = new Validator\NotEmpty(Validator\NotEmpty::STRING);
     $object = new ClassTest2();
     $this->assertFalse($valid->isValid($object));
     $valid = new Validator\NotEmpty(Validator\NotEmpty::OBJECT_STRING);
     $this->assertTrue($valid->isValid($object));
     $object = new ClassTest3();
     $this->assertFalse($valid->isValid($object));
 }
Example #18
0
 /**
  * @group ZF-11566
  */
 public function testArrayConfigNotationWithoutKey()
 {
     $filter = new NotEmpty(array('zero', 'string', 'boolean'));
     $this->assertFalse($filter->isValid(false));
     $this->assertTrue($filter->isValid(true));
     $this->assertTrue($filter->isValid(0));
     $this->assertTrue($filter->isValid(1));
     $this->assertTrue($filter->isValid(0.0));
     $this->assertTrue($filter->isValid(1.0));
     $this->assertFalse($filter->isValid(''));
     $this->assertTrue($filter->isValid('abc'));
     $this->assertFalse($filter->isValid('0'));
     $this->assertTrue($filter->isValid('1'));
     $this->assertTrue($filter->isValid(array()));
     $this->assertTrue($filter->isValid(array('xxx')));
     $this->assertTrue($filter->isValid(null));
 }
Example #19
0
 public function deletePersonAction()
 {
     $id = $this->params()->fromRoute('id', false);
     $group = $this->params()->fromRoute('group', false);
     $notEmpty_obj = new NotEmpty();
     if (!$notEmpty_obj->isValid($id)) {
         $id = false;
     }
     if (!$notEmpty_obj->isValid($group)) {
         $group = false;
     }
     if (!is_numeric($id) || $id <= 0) {
         $id = false;
     }
     if (!is_numeric($group) || $group <= 0) {
         $group = false;
     }
     if (!$id) {
         return $this->redirect()->toRoute('dashboard');
     }
     if (!$group) {
         return $this->redirect()->toRoute('dashboard');
     }
     $persons = $this->em->getRepository('Application\\Entity\\WebsiteTbPersonCalendar')->findBy(array('cali' => $group, 'peri' => $id));
     foreach ($persons as $person) {
         $this->em->remove($person);
     }
     $this->em->flush();
     return $this->redirect()->toRoute('view-group', array('id' => $group));
 }
Example #20
0
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $factory = new InputFactory();
         $inputFilter->add($factory->createInput(array('name' => 'userID', 'required' => true, 'filters' => array(array('name' => 'Int')))));
         //用户名
         $usernameif = $factory->createInput(array('name' => 'username', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
         $validatorChain = new ValidatorChain();
         $v = new StringLength(array('min' => 6, 'max' => 20, 'encoding' => 'UTF-8'));
         $v->setMessages(array(StringLength::TOO_SHORT => '用户名 \'%value%\' 太短了,至少需要6个字符', StringLength::TOO_LONG => '用户名 \'%value%\' 太长了,最多20个字符'));
         $validatorChain->attach($v);
         $v = new NotEmpty();
         $v->setMessage(array(NotEmpty::IS_EMPTY => '用户名不能为空'));
         $validatorChain->attach($v);
         $usernameif->setValidatorChain($validatorChain);
         $inputFilter->add($usernameif);
         //密码
         $psif = $factory->createInput(array('name' => 'upassword', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
         $validatorChain = new ValidatorChain();
         $v = new StringLength(array('min' => 6, 'max' => 20, 'encoding' => 'UTF-8'));
         $v->setMessages(array(StringLength::TOO_SHORT => '密码\'%value%\' 太短了,至少需要6个字符', StringLength::TOO_LONG => '密码 \'%value%\' 太长了,最多20个字符'));
         $validatorChain->attach($v);
         $v = new NotEmpty();
         $v->setMessage(array(NotEmpty::IS_EMPTY => '密码不能为空'));
         $validatorChain->attach($v);
         $psif->setValidatorChain($validatorChain);
         $inputFilter->add($psif);
         /* 原始方法不能改变默认错误信息
                    $inputFilter->add($factory->createInput(array(
                        'name'     => 'upassword',
                        'required' => true,
                        'filters'  => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 6,
                                    'max'      => 20,
                                ),
                            ),
                        ),
                    )));
            */
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }
Example #21
0
 /**
  * Create and return the validation failure message for required input.
  *
  * @return string[]
  */
 protected function prepareRequiredValidationFailureMessage()
 {
     $notEmpty = new NotEmpty();
     $templates = $notEmpty->getOption('messageTemplates');
     return [NotEmpty::IS_EMPTY => $templates[NotEmpty::IS_EMPTY]];
 }
 public function deleteAreaAction()
 {
     $id = $this->params()->fromRoute('id', false);
     $notEmpty_obj = new NotEmpty();
     if (!$notEmpty_obj->isValid($id)) {
         $id = false;
     }
     if (!is_numeric($id) || $id <= 0) {
         $id = false;
     }
     if (!$id) {
         return $this->redirect()->toRoute('dashboard');
     }
     $detail = $this->em->find('Application\\Entity\\WebsiteTbTechnicalReportDetail', $id);
     $id = $detail->getTeri()->getTeriId();
     $this->em->remove($detail);
     $this->em->flush();
     return $this->redirect()->toRoute('view-service', array('id' => $id));
 }
 public function editAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $email = $request->getPost('user-email', false);
         $empty_obj = new NotEmpty();
         if (!$empty_obj->isValid($email) || !$email) {
             throw new \RuntimeException("Not a valid email address given");
         }
         $email_obj = $this->em->getRepository('Application\\Entity\\ClientUser')->findOneByCluvEmail($email);
         if ($empty_obj->isValid($email_obj) && $email_obj->getCluiId() != $request->getPost('user-id', 0)) {
             throw new \RuntimeException("The email given is already in use. Try with another one.");
         }
         $client_obj = $this->em->find('Application\\Entity\\Client', $request->getPost('client-id', 0));
         $client_obj->setClivName(trim($request->getPost('client-name')));
         $this->em->persist($client_obj);
         $user_obj = $this->em->find('Application\\Entity\\ClientUser', $request->getPost('user-id', 0));
         $user_obj->setClii($client_obj)->setCluvUser(md5(trim($request->getPost('user-email'))))->setCluvEmail(trim($request->getPost('user-email')));
         $storedPass = $user_obj->getCluvPassword();
         $newPass = Encrypt::encrypt(trim($request->getPost('user-password')), trim($request->getPost('user-email')));
         if ($storedPass !== $newPass) {
             $user_obj->setCluvPassword($newPass);
         }
         $this->em->persist($user_obj);
         $this->em->flush();
     }
     return $this->redirect()->toRoute('view-client', array('id' => $request->getPost('client-id', 0)));
 }
 public function __construct($options = [])
 {
     parent::__construct($options);
     $this->setMessage('Este campo é requerido.', self::IS_EMPTY);
 }
Example #25
0
 public function __construct($options = null)
 {
     parent::__construct(self::NULL);
     $this->setMessage("Value can't be null", self::IS_EMPTY);
 }
Example #26
0
 public function getNotEmptyValidator()
 {
     if ($this->notEmptyValidator === NULL) {
         $validator = new NotEmpty();
         $validator->setOptions($this->getNotEmptyConfig())->setMessages(array(NotEmpty::IS_EMPTY => $this->getErrorMessage('NOTEMPTY::IS_EMPTY'), NotEmpty::INVALID => $this->getErrorMessage('NOTEMPTY::INVALID')));
         $this->setNotEmptyValidator($validator);
     }
     return $this->notEmptyValidator;
 }
 public function deleteAction()
 {
     if ($this->userId != 1) {
         return $this->redirect()->toRoute('dashboard');
     }
     $id = $this->params()->fromRoute('id', false);
     $notEmpty_obj = new NotEmpty();
     if (!$notEmpty_obj->isValid($id)) {
         $id = false;
     }
     if (!is_numeric($id) || $id <= 0) {
         $id = false;
     }
     if ($id === false) {
         return $this->redirect()->toRoute('dashboard');
     }
     $userDescription = $this->em->getRepository('Application\\Entity\\WebsiteTbSecurityUserDescription')->findOneBySusi($id);
     $user = $this->em->find('Application\\Entity\\WebsiteTbSecurityUser', $userDescription->getSusi()->getSusiId());
     $entity = $this->em->find('Application\\Entity\\WebsiteTbSecurityEntity', $user->getSeni()->getSeniId());
     $this->em->remove($userDescription);
     $this->em->remove($user);
     $this->em->remove($entity);
     $this->em->flush();
     return $this->redirect()->toRoute('user-list');
 }