コード例 #1
0
ファイル: RefreshToken.php プロジェクト: aainc/Behoimi
 public function get()
 {
     $request = $this->getRequest();
     $validationResult = \Hoimi\Validator::validate($request, array('refresh_token' => array('required' => true)));
     if ($validationResult) {
         throw new ValidationException($validationResult);
     }
     $accessToken = (object) array('access_token' => bin2hex(openssl_random_pseudo_bytes(25)), 'refresh_token' => $request->get('refresh_token'), 'expired_in' => AccessToken::EXPIRED_IN);
     $result = $this->getDatabaseSession()->executeNoResult('UPDATE access_tokens SET access_token = ?, created_at = UNIX_TIMESTAMP() WHERE refresh_token = ?', 'ss', array($accessToken->access_token, $accessToken->refresh_token));
     if ($result < 1) {
         throw new InvalidRefreshTokenException();
     }
     return new EntityResult(true, $accessToken, null);
 }
コード例 #2
0
ファイル: BasePager.php プロジェクト: aainc/Behoimi
 public function __construct(Gettable $request)
 {
     $validationResult = \Hoimi\Validator::validate($request, array('page' => array('required' => false, 'dataType' => 'integer', 'min' => 1), 'limit' => array('required' => false, 'dataType' => 'integer', 'min' => 1, 'max' => 1000), 'order' => array('required' => false, 'dataType' => 'string'), 'direction' => array('required' => false, 'dataType' => 'string', 'regex' => '#^(?:asc|desc)$#i')));
     if ($validationResult) {
         throw new ValidationException($validationResult);
     }
     if ($request->get('order')) {
         $list = $this->getColumns();
         if (!isset($list[$request->get('order')])) {
             $message = 'INVALID_FORMAT@^(?:' . implode('|', array_map(function ($row) {
                 return preg_quote($row);
             }, array_keys($list))) . ')$';
             throw new ValidationException(array('order' => $message));
         }
     }
     $this->request = $request;
 }
コード例 #3
0
ファイル: ExchangeToken.php プロジェクト: aainc/Behoimi
 public function get()
 {
     $request = $this->getRequest();
     $validationResult = Validator::validate($request, array('code' => array('required' => true, 'dataType' => 'string')));
     if ($validationResult) {
         throw new ValidationException($validationResult);
     }
     $this->getDatabaseSession()->executeNoResult('DELETE FROM authorization_codes WHERE expired_at < UNIX_TIMESTAMP()');
     $code = $this->getDatabaseSession()->find('SELECT id, authorized_application_id FROM authorization_codes WHERE code = ?', 's', array($request->get('code')));
     if (!$code) {
         throw new InvalidCodeException();
     }
     $accessToken = (object) array('access_token' => bin2hex(openssl_random_pseudo_bytes(25)), 'refresh_token' => bin2hex(openssl_random_pseudo_bytes(25)), 'expired_in' => AccessToken::EXPIRED_IN);
     $this->getDatabaseSession()->executeNoResult('INSERT INTO access_tokens (authorized_application_id, access_token, refresh_token, created_at) VALUES (?, ?, ?, UNIX_TIMESTAMP())', 'iss', array($code[0]->authorized_application_id, $accessToken->access_token, $accessToken->refresh_token));
     $this->getDatabaseSession()->executeNoResult('DELETE FROM authorization_codes WHERE id = ?', 'i', array($code[0]->id));
     return new EntityResult(true, $accessToken, null);
 }
コード例 #4
0
ファイル: BaseClientCommand.php プロジェクト: aainc/Behoimi
 public function run($args)
 {
     if (is_file('.accessToken')) {
         $tmp = (require '.accessToken');
         $args['accessToken'] = $tmp['accessToken'];
         $args['refreshToken'] = $tmp['refreshToken'];
     }
     if (!isset($args['accessToken']) || !isset($args['refreshToken'])) {
         print "need accessToken, need refreshToken";
         return;
     }
     ini_set('xdebug.overload_var_dump', 0);
     ini_set('xdebug.var_display_max_children', -1);
     ini_set('xdebug.var_display_max_data', -1);
     ini_set('xdebug.var_display_max_depth', -1);
     $validationResult = \Hoimi\Validator::validate(new ArrayContainer($args), $this->getValidatorDefinitions());
     if (!$validationResult) {
         try {
             $before = microtime();
             $client = $this->createClient($args['accessToken'], $args['refreshToken'], array(new AccessTokenPrinter()));
             $result = $this->operation($args, $client);
             $after = microtime();
             print "<<" . ($after - $before) * 1000 . ">>\n";
             if (isset($args['integration'])) {
                 $expected = $this->expected();
                 if (!is_callable($expected) && $this->expected() == $result || is_callable($expected) && $expected($result)) {
                     print get_class($this) . ":OK\n";
                 } elseif ($this->expected() !== self::SKIP_TEST) {
                     print get_class($this) . ":NG\n";
                     if (!is_callable($this->expected())) {
                         error_log("<<expected>>\n");
                         error_log(var_export($this->expected(), true));
                         error_log("\n\n<<actual>>\n");
                         error_log(var_export($result, true));
                         error_log("\n\n");
                     } else {
                         error_log(var_export($result, true));
                     }
                     throw new \RuntimeException(get_class($this) . ' test:failed');
                 } else {
                     print get_class($this) . ":skipped\n";
                 }
             } else {
                 var_dump($result);
             }
         } catch (\Loula\Exception $e) {
             print "<< Request Error>>\n";
             print $e->getStatus() . "\n";
             print "<< header \n";
             print $e->getHeader() . "\n";
             print "<< body \n";
             print $e->getBody() . "\n";
             print "<< request \n";
             var_dump($e->getRequest());
             throw $e;
         }
     } else {
         print "<< ValidationError >>\n";
         var_dump($validationResult);
     }
 }
コード例 #5
0
ファイル: ValidatorTest.php プロジェクト: aainc/Hoimi
 public function testValidate()
 {
     $request = new Request(array(), array('mahotora' => '1979-12-01', 'scruit' => 2, 'remila' => 3, 'zaolik' => ''));
     $result = \Hoimi\Validator::validate($request, array('hoimi' => array('required' => true), 'mahotora' => array('required' => true, 'dataType' => 'date', 'min' => '1979-11-30', 'max' => '1979-12-02'), 'scruit' => array('required' => true, 'dataType' => 'double', 'min' => 1, 'max' => 100), 'remila' => array('required' => true, 'dataType' => 'double'), 'zaolik' => array('required' => true, 'dataType' => 'string')));
     $this->assertSame(array('hoimi' => 'NOT_REQUIRED', 'zaolik' => 'NOT_REQUIRED'), $result);
 }