Exemplo n.º 1
0
 /**
  * @param Entity\Note $note
  * @param string $url
  * @param string $action
  * @param array $members
  * @return \Zend\Form\Form
  */
 public function getNoteForm(Entity\Note $note, $url = '', $action = 'add', $members = null)
 {
     if (is_null($this->noteForm)) {
         $builder = new AnnotationBuilder($this->getEntityManager());
         $this->noteForm = $builder->createForm($note);
         $this->noteForm->setAttribute('action', $url);
         $this->noteForm->setAttribute('id', 'noteForm');
         $this->noteForm->setHydrator(new DoctrineObject($this->getEntityManager(), 'Secretary\\Entity\\Note'));
         $this->noteForm->bind($note);
         if ($action == 'edit' && $note->getPrivate() === false) {
             $this->noteForm->remove('private');
             $group = $note->getGroup();
             $membersString = $this->getMembersString(array_keys($members));
             $this->noteForm->get('groupHidden')->setValue($group->getId());
             $this->noteForm->get('members')->setValue($membersString);
             $this->noteForm->getInputFilter()->remove('__initializer__');
             $this->noteForm->getInputFilter()->remove('__cloner__');
             $this->noteForm->getInputFilter()->remove('__isInitialized__');
             $this->noteForm->getInputFilter()->remove('lazyPropertiesDefaults');
         } else {
             $this->noteForm->get('private')->setAttribute('required', false);
             $this->noteForm->getInputFilter()->get('private')->setRequired(false);
         }
     }
     return $this->noteForm;
 }
 /**
  * @param Collection $collection
  */
 protected function configureInputFilter(Collection $collection)
 {
     // Make it a collection input filter
     $inputFilter = new CollectionInputFilter();
     $inputFilter->setIsRequired(false);
     // Add the input filter of the target document as the real input filter:
     $targetElement = $collection->getTargetElement();
     if ($targetElement instanceof InputFilterProviderInterface) {
         $configuredFilter = $targetElement->getInputFilterSpecification();
         $inputFilter->setInputFilter($configuredFilter);
     }
     // Replace the current input filter in the actual form:
     $collectionName = $collection->getName();
     $formFilter = $this->form->getInputFilter();
     $formFilter->remove($collectionName);
     $formFilter->add($inputFilter, $collectionName);
 }
Exemplo n.º 3
0
 public function testAddNonBaseFieldsetObjectInputFilterToFormInputFilter()
 {
     $fieldset = new Fieldset('foobar');
     $fieldset->add(new Element('foo'));
     $fieldset->setUseAsBaseFieldset(false);
     $this->form->add($fieldset);
     $inputFilterFactory = new InputFilterFactory();
     $inputFilter = $inputFilterFactory->createInputFilter(array('foo' => array('name' => 'foo', 'required' => true)));
     $model = new TestAsset\ValidatingModel();
     $model->setInputFilter($inputFilter);
     $this->form->bind($model);
     $this->assertInstanceOf('Zend\\InputFilter\\InputFilterInterface', $this->form->getInputFilter()->get('foobar'));
 }
Exemplo n.º 4
0
 public function getInputFilter()
 {
     parent::getInputFilter();
     if (!$this->filter) {
         $inputFilter = new InputFilter();
         $inputFactory = new InputFactory();
         $inputFilter->add($inputFactory->createInput(array('name' => 'name', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => '"Name" is required')))))));
         $inputFilter->add($inputFactory->createInput(array('name' => 'email', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'EmailAddress', 'options' => array('messages' => array('emailAddressInvalidFormat' => 'Email format is not valid'))), array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => '"Email" is required')))))));
         $inputFilter->add($inputFactory->createInput(array('name' => 'inquiry', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => '"Question" is required')))))));
         $this->filter = $inputFilter;
     }
     return $this->filter;
 }
Exemplo n.º 5
0
 public function getInputFilter()
 {
     parent::getInputFilter();
     if ($this->filter == null) {
         $this->filter = new InputFilter();
         $this->filter->add(array("name" => "firstname", "required" => true, 'validators' => array(array('name' => 'Alpha', 'options' => array("allowWhiteSpace" => true)), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 3, 'max' => 50)))));
         $this->filter->add(array("name" => "lastname", "required" => true, 'validators' => array(array('name' => 'Alpha', 'options' => array("allowWhiteSpace" => true)), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 3, 'max' => 50)))));
         $this->filter->add(array("name" => "email", "required" => true, "validators" => array(array("name" => 'EmailAddress'))));
         $this->filter->add(array('name' => "phone", "required" => true, 'validators' => array(array('name' => 'regex', 'options' => array("pattern" => '/^[0-9]{8,15}$/', "message" => "numero invalide")))));
         $this->filter->add(array('name' => 'password', 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 6, 'max' => 50)))));
     }
     return $this->filter;
 }
Exemplo n.º 6
0
 public function getInputFilter()
 {
     $formInputFilter = parent::getInputFilter();
     //email should not exists (register)
     $emailInput = $formInputFilter->get('user')->get('email');
     $emailUnique = new \DoctrineModule\Validator\NoObjectExists(array('object_manager' => $this->em, 'object_repository' => $this->em->getRepository('CasasoftAuth\\Entity\\User'), 'fields' => 'email'));
     $emailUnique->setMessage('Diese E-Mail-Adresse wird bereits verwendet.', 'objectFound');
     $emailInput->getValidatorChain()->attach($emailUnique);
     $usernameInput = $formInputFilter->get('user')->get('username');
     $usernameUnique = new \DoctrineModule\Validator\NoObjectExists(array('object_manager' => $this->em, 'object_repository' => $this->em->getRepository('CasasoftAuth\\Entity\\User'), 'fields' => 'username'));
     $usernameUnique->setMessage('Dieser Benutzername wird bereits verwendet.', 'objectFound');
     $usernameInput->getValidatorChain()->attach($usernameUnique);
     return $formInputFilter;
 }
Exemplo n.º 7
0
 /**
  * Since the input filter was set how I want when adding the captcha element,
  * and I want to adjust the other default filters, I have overriden this method.
  * Not sure how I feel about it.
  *
  * @param void
  * @return Zend\InputFilter\InputFilter
  * @override
  * @todo Fix this up
  **/
 public function getInputFilter()
 {
     if ($this->_filter == null) {
         $filter = parent::getInputFilter();
         //What the h4ck!?  Maybe I can just modify these filters instead of re-adding them?
         $filter->remove('name')->remove('email')->remove('comment');
         $factory = new InputFactory();
         $filter->add($factory->createInput(array('name' => 'name', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 50))))));
         $filter->add($factory->createInput(array('name' => 'email', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'EmailAddress', 'options' => array('message' => array('Please enter a valid email address.  Thanks!'))), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 100))))));
         $filter->add($factory->createInput(array('name' => 'comment', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 3000))))));
         $this->_filter = $filter;
     }
     return $this->_filter;
 }
Exemplo n.º 8
0
 public function getInputFilter()
 {
     if ($this->filter == null) {
         $this->filter = new InputFilter();
         $inputFilter = parent::getInputFilter();
         $email = new Input('email');
         $email->setRequired(true);
         $email->setAllowEmpty(false);
         $objectExists = new ObjectExists(array('object_repository' => $this->objectManager->getRepository(User::getClass()), 'fields' => 'email'));
         $objectExists->setMessage($this->translator->translate('forgotPassword.email.notExists'), ObjectExists::ERROR_NO_OBJECT_FOUND);
         $emailAddress = new EmailAddress();
         $emailAddress->setMessage($this->translator->translate('forgotPassword.email.invalidFormat'), $emailAddress::INVALID_FORMAT);
         $email->getValidatorChain()->attach($emailAddress, true)->attach($objectExists);
         $this->filter->add($email);
     }
     return $this->filter;
 }
Exemplo n.º 9
0
 protected function buildForm()
 {
     $form = new Form();
     $parameters = $this->getUserParameters();
     // add the elements to the form
     foreach ($parameters as $parameter) {
         $element = $this->buildElement($parameter);
         $form->add($element);
     }
     // modify the input filter
     foreach ($parameters as $parameter) {
         $filter = $form->getInputFilter()->get($parameter->name);
         $filter->setAllowEmpty($parameter->isAllowBlank());
     }
     $submit = new \Zend\Form\Element\Submit('ViewReportControl');
     $submit->setValue('View Report');
     $form->add($submit);
     $this->form = $form;
     return $this;
 }
Exemplo n.º 10
0
 public function resetAction()
 {
     $request = $this->getRequest();
     $email = urldecode($request->getQuery()->email);
     $token = $request->getQuery()->token;
     if (empty($email) || empty($token)) {
         $this->flashMessenger()->addErrorMessage($this->translator->translate('The link you\'re using is broken'));
         return $this->redir()->toRoute('admin/default', array('controller' => 'log', 'action' => 'in'));
     }
     $sl = $this->getServiceLocator();
     $entityManager = $sl->get('entity-manager');
     //check if the token is valid
     $passwordResetClassName = get_class(new PasswordResets(null, null));
     $resetPassword = $entityManager->find($passwordResetClassName, ['email' => $email, 'token' => $token]);
     if (!$resetPassword) {
         $this->flashMessenger()->addErrorMessage($this->translator->translate('The link you\'re using is out of date or corrupted, please create another password request'));
         return $this->redir()->toRoute('admin/default', array('controller' => 'log', 'action' => 'forgotten'));
     }
     $createdAt = $resetPassword->getCreatedAt();
     $date = new \DateTime();
     $date->sub(new \DateInterval('PT24H'));
     if ($date > $createdAt) {
         $this->flashMessenger()->addErrorMessage($this->translator->translate('The link you\'re using is out of date, please create another password request'));
         return $this->redir()->toRoute('admin/default', array('controller' => 'log', 'action' => 'forgotten'));
     }
     $userClassEntity = $sl->get('user-entity');
     $user = $entityManager->getRepository(get_class($userClassEntity))->findOneByEmail('*****@*****.**');
     if (!$user) {
         $this->flashMessenger()->addErrorMessage($this->translator->translate('There is no user with email: ' . $email . '. You have probably changed the email recently.'));
         return $this->redir()->toRoute('admin/default', array('controller' => 'log', 'action' => 'forgotten'));
     }
     $form = new Form('reset_password');
     $form->add(array('type' => 'Admin\\Form\\UserPassword', 'name' => 'password_fields'));
     $form->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('value' => 'Edit')));
     $form->getInputFilter()->get('password_fields')->get('password_repeat')->setRequired(true);
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $user->setUpass($form->getInputFilter()->get('password_fields')->get('password')->getValue());
             $entityManager->getRepository($passwordResetClassName)->deleteAllForEmail($email);
             $entityManager->flush();
             $this->flashMessenger()->addSuccessMessage($this->getTranslator()->translate('The password has been changed successfully.'));
             $this->redir()->toRoute('admin/default', array('controller' => 'log', 'action' => 'in'));
         }
     }
     return ['form' => $form];
 }