/** * @return $this */ protected function emailExist() { $recordExistsValidator = new ObjectExists(array('object_repository' => $this->sm->get('Doctrine\\ORM\\EntityManager')->getRepository('User\\Entity\\User'), 'fields' => 'email')); $recordExistsValidator->setMessage('User with this email are not exists', ObjectExists::ERROR_NO_OBJECT_FOUND); $this->add(array('name' => 'email', 'required' => true, 'validators' => array(array('name' => 'EmailAddress'), $recordExistsValidator), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')))); return $this; }
/** * Forgot form factory * * @param ServiceLocatorInterface $serviceLocator * @return ForgotForm */ public function createService(ServiceLocatorInterface $serviceLocator) { $entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager'); $options = $serviceLocator->get('User\\Password\\Options'); $zfcUserOptions = $serviceLocator->get('zfcuser_module_options'); $validator = new ObjectExists(['object_repository' => $entityManager->getRepository($zfcUserOptions->getUserEntityClass()), 'fields' => 'email']); $validator->setMessage('The email address you entered was not found.'); $form = new ForgotForm(null); $form->setInputFilter(new ForgotFormFilter($validator, $options)); return $form; }
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; }