/**
  * @param In $inputStream The message input stream
  * @param MessageInterface $message The message to map the data into
  *
  * @throws \Avalonia\Component\Message\Exception\MapperInvalidArgumentException if the given $rawData is not of the good type
  * @throws \Avalonia\Component\Message\Exception\MapperInvalidDataException if the given $rawData doesn't not fetch the required format
  *
  * Maps the given stream into a message
  */
 public function mapStreamToMessage(In $inputStream, MessageInterface $message)
 {
     $start = $inputStream->read(strlen(static::HTTP_RESPONSE_STATUS_START));
     if (static::HTTP_RESPONSE_STATUS_START === $start) {
         $statusLine = $start . $this->readHttpLine($inputStream, false);
         if (0 === preg_match(static::HTTP_RESPONSE_STATUS_PATTERN, $statusLine, $parsedStatusLine)) {
             throw new HttpMapperInvalidStatusException(sprintf("The HTTP command line is not valid: \"%s. Expected format: HTTP/1.0|1.1 CODE MESSAGE", $statusLine));
         }
         $message->setHeader(HttpMessage::HEADER_HTTP_STATUS_CODE, (int) $parsedStatusLine["code"]);
         $message->setHeader(HttpMessage::HEADER_HTTP_STATUS_MESSAGE, $parsedStatusLine["message"]);
         $message->setHeader(HttpMessage::HEADER_HTTP_VERSION, $parsedStatusLine["version"]);
         // Then read headers and body
         $this->readHttpHeaderAndBody($inputStream, $message);
     } else {
         $message->setHeader(HttpMessage::HEADER_HTTP_VERSION, static::DEFAULT_HTTP_VERSION);
         $message->setBody($start . $inputStream->readAll());
     }
 }
 /**
  * @param In $inputStream
  * @param MessageInterface $message
  *
  * @throws HttpMapperInvalidHeaderException
  * @throws MapperInvalidDataException
  * @throws MapperMaxLineLengthException
  *
  * Parse http headers and body from the stream, and map it to $message
  */
 protected function readHttpHeaderAndBody(In $inputStream, MessageInterface $message)
 {
     while (!$inputStream->eof()) {
         try {
             $line = $this->readHttpLine($inputStream, false, $offset);
         } catch (MapperInvalidDataEofFoundException $e) {
             // If this exception is caught, it means that the message doesn't have a body.
             // So parse the remaining data in the buffer
             $line = $e->getRemainingBufferData();
         }
         if ('' === $line) {
             // We reached the body
             $message->setBody($inputStream->readAll());
             // stop the loop as the mapping is finished
             break;
         } elseif (0 === preg_match(static::HTTP_HEADER_PATTERN, $line, $parsedHeader)) {
             throw new HttpMapperInvalidHeaderException(sprintf("The given HTTP header line is not valid: \"%s\". Expected format: HEADER-NAME: VALUE.", $line));
         }
         $message->setHeader($parsedHeader["header"], $parsedHeader["content"]);
     }
 }
Example #3
0
 public function change_password()
 {
     $this->cut_notlogged();
     $this->user = new UsersModel();
     if (!empty($_POST)) {
         // Check for CSRF first.
         Secure::csrf_checknredir($_POST['csrf_tkn']);
         $in = new In();
         $validation = $in->validate_input($_POST, array('password' => array('required' => 'true', 'min' => '6', 'max' => '16'), 'password2' => array('required' => 'true', 'equal_field' => 'password')));
         if ($validation) {
             $salt = Secure::salt(32);
             $upd_user['password'] = Secure::do_hash($_POST['password'], $salt);
             $upd_user['salt'] = $salt;
             $upd_user['id'] = $_SESSION['user']['id'];
             $this->user->update($upd_user);
             //
             Out::flash('Password updated.');
             header("Location: " . ROOT_URI . '/admin/users');
             exit;
         } else {
             // output errors
             $ers = '';
             foreach ($in->errors as $er) {
                 $ers .= $er . "<br />";
             }
             Out::flash($ers);
             header("Location: " . ROOT_URI . "/admin/users/change_password");
             exit;
         }
     }
     //  end if POST
     // which user to edit
     $id = $_SESSION['user']['id'];
     $user2edit = $this->user->get_user($id);
     $this->set_view_var($user2edit);
 }
Example #4
0
 /**
  * @expectedException Respect\Validation\Exceptions\InException
  * @expectedExceptionMessage "x" must be in { "foo", "bar" }
  */
 public function testInCheckExceptionMessageWithArray()
 {
     $v = new In(array('foo', 'bar'));
     $v->assert('x');
 }
Example #5
0
 /**
  * @dataProvider providerForNotIn
  * @expectedException Respect\Validation\Exceptions\InException
  */
 public function testInvalidInChecksShouldThrowInException($input, $options, $strict = false)
 {
     $v = new In($options, $strict);
     $this->assertFalse($v->__invoke($input));
     $this->assertFalse($v->assert($input));
 }
Example #6
0
 public function testShouldValidateValueIsOutOfTheList()
 {
     $haystack = array(1, 2, 3, 4, 5);
     $filter = new In($haystack);
     $this->assertFalse($filter->isValid(6));
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 protected function isConditionAllowed($context)
 {
     return !parent::isConditionAllowed($context);
 }
Example #8
0
 /**
  * @dataProvider providerForNotIn
  * @expectedException Respect\Validation\Exceptions\InException
  */
 public function test_invalid_in_checks_should_throw_InException($input, $options, $strict = false)
 {
     $v = new In($options, $strict);
     $this->assertFalse($v->validate($input));
     $this->assertFalse($v->assert($input));
 }
Example #9
0
 public function login()
 {
     $this->app->config->layout = "default";
     if ($this->check_logged()) {
         if ($this->isAdmin()) {
             header("Location: " . ROOT_URI . "/admin");
             exit;
         } else {
             header("Location: " . ROOT_URI);
             exit;
         }
     }
     if (!empty($_POST)) {
         // Check for CSRF first.
         Secure::csrf_checknredir($_POST['csrf_tkn']);
         $this->user = new UsersModel();
         $in = new In();
         $validation = $in->validate_input($_POST, array('email' => array('required' => 'true', 'valid_email' => 'true'), 'password' => array('required' => 'true')));
         if ($validation) {
             $login = $this->user->login($_POST['email'], $_POST['password']);
             if ($login) {
                 if ($this->isAdmin()) {
                     Out::flash('Welcome admin');
                     header("Location: " . ROOT_URI . '/admin');
                     exit;
                 } else {
                     Out::flash('Welcome user');
                     header("Location: " . ROOT_URI);
                     exit;
                 }
             } else {
                 Out::flash('Wrong login.');
             }
         } else {
             // output errors
             $ers = '';
             foreach ($in->errors as $er) {
                 $ers .= $er . "<br />";
             }
             Out::flash($ers);
         }
     }
 }