Exemplo n.º 1
0
 /**
  * @param array $data
  *
  * @return bool
  */
 public function isValid($data)
 {
     if ($data === null) {
         $data = [];
     }
     $this->inputFilter->setData($data);
     return $this->inputFilter->isValid($data);
 }
 /**
  * Validates the form data using the provided input filter.
  *
  * If validation errors are found, the form is populated with the corresponding error messages.
  * Form values are updated with the clean values provided by the filter.
  *
  * @param  Form $form
  * @return boolean
  */
 public function validate(Form $form)
 {
     $this->inputFilter->setData($form->values());
     if (!($isValid = $this->inputFilter->isValid())) {
         $form->setErrorMessages($this->inputFilter->getMessages());
         return $isValid;
     }
     $form->submit($this->inputFilter->getValues());
     return $isValid;
 }
 /**
  * @param MvcEvent $e
  * @return mixed|void
  */
 public function onDispatch(MvcEvent $e)
 {
     $this->inputFilter->setData($this->params()->fromPost());
     if (!$this->inputFilter->isValid()) {
         $this->flashMessenger()->addErrorMessage($this->inputFilter->getMessages());
         return $this->redirect()->toRoute('frontend');
     }
     try {
         $this->pagesResource->download($this->inputFilter->getValue('site_url'));
         $this->flashMessenger()->addSuccessMessage('Url successfully queued for download all images');
     } catch (ApiException $e) {
         $this->flashMessenger()->addErrorMessage($e->getMessage());
     }
     $this->redirect()->toRoute('frontend');
 }
Exemplo n.º 4
0
 public function isValid()
 {
     if (!is_null($this->isValid)) {
         return $this->isValid;
     }
     return $this->isValid = parent::isValid();
 }
 /**
  * Override isValid to provide conditional input checking
  * @return bool
  */
 public function isValid()
 {
     if (!$this->isValidService()) {
         return false;
     }
     return parent::isValid();
 }
Exemplo n.º 6
0
 public function uploadImageAction()
 {
     $this->checkAuth();
     $request = $this->getRequest();
     if ($request->isPost()) {
         // File upload input
         $file = new FileInput('avatar');
         // Special File Input type
         $file->getValidatorChain()->attach(new Validator\File\UploadFile());
         $file->getFilterChain()->attach(new Filter\File\RenameUpload(array('target' => './public/files/users/avatar/origin/', 'use_upload_name' => true, 'randomize' => true)));
         // Merge $_POST and $_FILES data together
         $request = new Request();
         $postData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $inputFilter = new InputFilter();
         $inputFilter->add($file)->setData($postData);
         if ($inputFilter->isValid()) {
             // FileInput validators are run, but not the filters...
             $data = $inputFilter->getValues();
             // This is when the FileInput filters are run.
             $avatar = basename($data['avatar']['tmp_name']);
             $this->databaseService->updateAvatar($this->user->id, $avatar);
             $this->user->avatar = $avatar;
         } else {
             // error
         }
     }
     return $this->redirect()->toRoute('profile');
 }
Exemplo n.º 7
0
 /**
  * Perform any processing or data manipulation needed before render.
  *
  * A response helper object will be passed to this method to allow you to
  * easily add success messages or redirects.  This helper should be used
  * to handle these kinds of actions so that you can easily test your
  * page's code.
  *
  * @param ResponseHelper $responseHelper
  * @return ResponseHelper|null
  */
 public function process(ResponseHelper $responseHelper)
 {
     $isCurrentUser = $this->row->get('user_id') === Pimple::getResource('user')->get('user_id');
     if (!$this->component->getPermissions()->can('edit') && !$isCurrentUser) {
         return $responseHelper->redirectToUrl('/admin');
     }
     if ($this->request->isPost()) {
         $this->inputFilter->setData($this->request->getPost());
         if ($this->inputFilter->isValid()) {
             $this->row->hashPassword($this->request->getPost('password'))->save();
             if ($isCurrentUser) {
                 return $responseHelper->redirectToUrl('/admin');
             } else {
                 return $responseHelper->redirectToAdminPage('index');
             }
         }
     }
 }
 public function isValid()
 {
     $fields = ['id', 'mode'];
     $mode = $this->getMode();
     if ($mode == 'timecreated') {
         $fields[] = 'timecreated';
     }
     $this->setValidationGroup($fields);
     return parent::isValid();
 }
 public function isValid()
 {
     $type = $this->getType();
     if ($type) {
         $field = $this->_getRelationshipInput($type);
         if ($field) {
             $this->setValidationGroup(['id', 'type', $field]);
         }
     }
     return parent::isValid();
 }
Exemplo n.º 10
0
 /**
  * {@inheritDoc}
  */
 public function isValid($context = null)
 {
     $valid = parent::isValid($context);
     if (!$valid) {
         return $valid;
     }
     $validators = $this->getValidatorChain();
     $valid = $validators->isValid(new \ArrayObject($this->getValues()), $context);
     if (!$valid) {
         $validators->getMessages();
     }
     return $valid;
 }
Exemplo n.º 11
0
 /**
  * __invoke
  *
  * @param Request       $request
  * @param Response      $response
  * @param callable|null $out
  *
  * @return mixed
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $filterConfig = $this->getOption($request, 'config', []);
     $inputFilter = new InputFilter();
     $factory = $inputFilter->getFactory();
     foreach ($filterConfig as $field => $config) {
         $inputFilter->add($factory->createInput($config));
     }
     $dataModel = $request->getParsedBody();
     $inputFilter->setData($dataModel);
     if ($inputFilter->isValid()) {
         return $out($request, $response);
     }
     $messages = new ZfInputFilterMessageResponseModels($inputFilter, $this->getOption($request, 'primaryMessage', 'An Error Occurred'), $this->getOption($request, 'messageParams', []));
     return $this->getResponseWithDataBody($response, $messages);
 }
Exemplo n.º 12
0
 public function isValid()
 {
     $valid = parent::isValid();
     if ($this->checkPassword) {
         $password = $this->get('password');
         $confirm_password = $this->get('confirm_password');
         if ($password->getValue() != $confirm_password->getValue()) {
             $valid = false;
             $password->setErrorMessage('Passwords did not match');
             if (!isset($this->invalidInputs[$password->getName()])) {
                 $this->invalidInputs[$password->getName()] = $password;
             }
             $confirm_password->setErrorMessage('Passwords did not match');
             if (!isset($this->invalidInputs[$confirm_password->getName()])) {
                 $this->invalidInputs[$confirm_password->getName()] = $confirm_password;
             }
         }
     }
     return $valid;
 }
Exemplo n.º 13
0
 /**
  * Check if login form is valid
  *  - first call parent to validate fields
  *  - get user by identity and validate
  * @return bool
  */
 public function isValid()
 {
     $valid = parent::isValid();
     if ($valid) {
         $identity = $this->get('identity')->getValue();
         $credential = $this->get('credential')->getValue();
         $user = $this->getUserByIdentity($identity);
         if (!$user) {
             $this->invalidInputs['identity'] = $this->get('identity');
             $this->get('identity')->setErrorMessage('Invalid identity or credential supplied.');
             return false;
         }
         $salt = $user->getPasswordSalt();
         $password = $user->getPassword();
         if (!$this->_isValidCredential($password, $salt, $credential)) {
             $this->invalidInputs['identity'] = $this->get('identity');
             $this->get('identity')->setErrorMessage('Invalid identity or credential supplied.');
             return false;
         }
     }
     return $valid;
 }
 public function isValid($context = null)
 {
     $data = $this->data;
     if (null === $data) {
         return parent::isValid($context);
     }
     if ($data instanceof Traversable) {
         $data = iterator_to_array($data);
     }
     if (is_object($data)) {
         $data = (array) $data;
     }
     if (!isset($data['dsn'])) {
         $data['dsn'] = null;
     }
     if (isset($data['dsn_type']) && 'Mongo' === $data['dsn_type']) {
         if (!isset($data['database'])) {
             $data['database'] = null;
         }
     }
     $this->setData($data);
     return parent::isValid($context);
 }
Exemplo n.º 15
0
 /**
  * Is the data set valid?
  *
  * @throws RuntimeException
  * @return bool
  */
 public function isValid()
 {
     if (true === ($valid = parent::isValid())) {
         $validator = new Callback(array('callback' => function ($values) {
             if (isset($values['query']) || isset($values['latitude']) && isset($values['longitude']) || isset($values['id'])) {
                 return true;
             }
         }, 'messages' => array(Callback::INVALID_VALUE => 'Requires a query, id, or latitude and longitude')));
         if (true === ($valid = $validator->isValid($this->getValues()))) {
             $this->validInputs['atLeastOne'] = $validator;
         } else {
             $this->invalidInputs['atLeastOne'] = $validator;
         }
     }
     return $valid;
 }
 /**
  * Example of simple input filter message using getApiResponse() hydrator
  *
  * @param $exampleData
  *
  * @return \Reliv\RcmApiLib\Http\ApiResponse
  */
 protected function getApiResponseInputFilterExample($exampleData)
 {
     $email = new Input('email');
     $email->getValidatorChain()->attach(new EmailAddress());
     $password = new Input('password');
     $password->getValidatorChain()->attach(new StringLength(['min' => 8]));
     $inputFilter = new InputFilter();
     $inputFilter->add($email)->add($password)->setData($exampleData);
     // Do validation
     $inputFilter->isValid();
     /* Return the response */
     return $this->getApiResponse($exampleData, 400, $inputFilter);
 }
Exemplo n.º 17
0
 public function addfileAction()
 {
     $this->checkAuth();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $file_attach = new FileAttachment();
         $file_attach->user_create = $this->auth->getIdentity()->id;
         $file_attach->date_create = date('Y-m-d H:i:s');
         $file_attach->last_date = $file_attach->date_create;
         $file_attach->last_user = $this->auth->getIdentity()->id;
         // info pay
         $file_attach->task_id = $request->getPost('task_id');
         $file_attach->permission_option = $request->getPost('permission_option');
         if ($this->isLevel2() != true) {
             $permission = $this->databaseService->getPermissionUser($file_attach->task_id, $file_attach->user_create);
             if ($permission == Config::FILE_PERMISSION_ERROR) {
                 return new JsonModel(array());
             }
             if ($permission == Config::FILE_PERMISSION_CUSTUMER) {
                 $file_attach->permission_option = Config::FILE_PERMISSION_CUSTUMER;
             }
             if ($permission == Config::FILE_PERMISSION_PROVIDER) {
                 $file_attach->permission_option = Config::FILE_PERMISSION_PROVIDER;
             }
         }
         // File upload input
         $file = new FileInput('file_name');
         // Special File Input type
         $file->getValidatorChain()->attach(new Validator\File\UploadFile());
         $file->getFilterChain()->attach(new Filter\File\RenameUpload(array('target' => '.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id, 'use_upload_name' => true, 'randomize' => true)));
         if (!file_exists('.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id)) {
             mkdir('.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id, 0700, true);
         }
         // Merge $_POST and $_FILES data together
         $request = new Request();
         $postData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $inputFilter = new InputFilter();
         $inputFilter->add($file)->setData($postData);
         if ($inputFilter->isValid()) {
             // FileInput validators are run, but not the filters...
             $data = $inputFilter->getValues();
             // This is when the FileInput filters are run.
             $file_attach->real_name = basename($data['file_name']['tmp_name']);
             $file_attach->file_name = basename($data['file_name']['name']);
             $result = $this->databaseService->addFileAttachment($file_attach);
             $file_attach->id = $result->getGeneratedValue();
             $this->databaseService->addFileLog($this->auth->getIdentity()->id, $file_attach, Config::PAY_INFO_COMMON);
         }
     }
     return new JsonModel(array());
 }
Exemplo n.º 18
0
    /**
     * @param  mixed|null $context
     * @return bool
     */
    public function isValid($context = null)
    {
        $result = parent::isValid($context);

        if ($result === true) {
            foreach ($this->nestedInputFilters as $name => $nestedInputFilter) {
//                if (is_int($this->getValue($name))) {
//                    continue;
//                }
                $nestedResult = $nestedInputFilter->isValid($context);
                if (!$nestedResult) {
                    $result = false;
                }
            }
        }

        return $result;
    }
Exemplo n.º 19
0
 /**
  * Is the data set valid?
  *
  * @return bool
  */
 public function isValid()
 {
     // When there's an invalid data type, it should immediately report as invalid.
     if ($this->invalidDataTypeException !== null) {
         return false;
     }
     // When there's no data and the filter itself is not required,
     // it should immediately report as valid.
     if (!$this->data && !$this->isRequired()) {
         return true;
     }
     // Don't filter at all when "inputsToFilter" is set to empty array
     if (!$this->needsFiltering()) {
         return true;
     }
     return parent::isValid();
 }