示例#1
0
文件: Revoke.php 项目: virusvn/fusio
    public function onPost()
    {
        $header = $this->getHeader('Authorization');
        $parts = explode(' ', $header, 2);
        $type = isset($parts[0]) ? $parts[0] : null;
        $token = isset($parts[1]) ? $parts[1] : null;
        if ($type == 'Bearer') {
            $sql = 'SELECT id,
					       appId,
					       userId,
					       scope
					  FROM fusio_app_token
					 WHERE token = :token';
            $row = $this->connection->fetchAssoc($sql, array('token' => $token));
            // the token must be assigned to the user
            if (!empty($row) && $row['appId'] == $this->appId && $row['userId'] == $this->userId) {
                $this->tableManager->getTable('Fusio\\Backend\\Table\\App\\Token')->removeTokenFromApp($this->appId, $row['id']);
                $this->setBody(array('success' => true));
            } else {
                throw new StatusCode\BadRequestException('Invalid token');
            }
        } else {
            throw new StatusCode\BadRequestException('Invalid token type');
        }
    }
示例#2
0
 /**
  * Returns the GET response
  *
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doGet(Version $version)
 {
     $startIndex = $this->getParameter('startIndex', Validate::TYPE_INTEGER) ?: null;
     $filter = Log\QueryFilter::create($this->getParameters());
     $condition = $filter->getCondition();
     $table = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Log');
     $table->setRestrictedFields(['header', 'body']);
     return array('totalItems' => $table->getCount($condition), 'startIndex' => $startIndex, 'entry' => $table->getAll($startIndex, null, 'id', Sql::SORT_DESC, $condition));
 }
示例#3
0
文件: Entity.php 项目: uqiauto/fusio
 /**
  * Returns the GET response
  *
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doGet(Version $version)
 {
     $logId = (int) $this->getUriFragment('log_id');
     $log = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Log')->get($logId);
     if (!empty($log)) {
         // append errors
         $log['errors'] = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Log')->getErrors($log['id']);
         return $log;
     } else {
         throw new StatusCode\NotFoundException('Could not find log');
     }
 }
示例#4
0
文件: Token.php 项目: virusvn/fusio
 public function doRemove()
 {
     $appId = $this->getUriFragment('app_id');
     $tokenId = $this->getUriFragment('token_id');
     $app = $this->tableManager->getTable('Fusio\\Backend\\Table\\App')->get($appId);
     if ($app instanceof RecordInterface) {
         $this->tableManager->getTable('Fusio\\Backend\\Table\\App\\Token')->removeTokenFromApp($appId, $tokenId);
         $this->setBody(array('success' => true, 'message' => 'Removed token successful'));
     } else {
         throw new NotFoundException('Invalid app');
     }
 }
示例#5
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->getValidator()->validate($record);
     $schemaTable = $this->tableManager->getTable('Fusio\\Backend\\Table\\Schema');
     $schemaTable->create(array('name' => $record->getName(), 'source' => $record->getSource(), 'cache' => $this->schemaParser->parse($record->getSource(), $record->getName())));
     return array('success' => true, 'message' => 'Schema successful created');
 }
示例#6
0
 protected function insertDefaultScopes($appId, $userId)
 {
     $scopes = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\User\\Scope')->getByUserId($userId);
     $table = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\App\\Scope');
     foreach ($scopes as $scope) {
         $table->create(array('appId' => $appId, 'scopeId' => $scope['id']));
     }
 }
示例#7
0
文件: Entity.php 项目: uqiauto/fusio
 protected function checkLocked($action)
 {
     if ($action['status'] == Action::STATUS_LOCKED) {
         $paths = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes\\Action')->getDependingRoutePaths($action['id']);
         $paths = implode(', ', $paths);
         throw new StatusCode\ConflictException('Action is locked because it is used by a route. Change the route status to "Development" or "Closed" to unlock the schema. The following routes reference this schema: ' . $paths);
     }
 }
示例#8
0
文件: Entity.php 项目: virusvn/fusio
 protected function insertScopes($appId, $scopes)
 {
     $scopes = $this->tableManager->getTable('Fusio\\Backend\\Table\\Scope')->getByNames($scopes);
     $table = $this->tableManager->getTable('Fusio\\Backend\\Table\\App\\Scope');
     foreach ($scopes as $scope) {
         $table->create(array('appId' => $appId, 'scopeId' => $scope['id']));
     }
 }
示例#9
0
文件: Entity.php 项目: uqiauto/fusio
 protected function insertScopes($userId, $scopes)
 {
     if (!empty($scopes) && is_array($scopes)) {
         $scopeTable = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\User\\Scope');
         $scopes = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Scope')->getByNames($scopes);
         foreach ($scopes as $scope) {
             $scopeTable->create(array('userId' => $userId, 'scopeId' => $scope['id']));
         }
     }
 }
示例#10
0
文件: Entity.php 项目: uqiauto/fusio
 /**
  * Returns the DELETE response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doDelete(RecordInterface $record, Version $version)
 {
     $connectionId = (int) $this->getUriFragment('connection_id');
     $connection = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Connection')->get($connectionId);
     if (!empty($connection)) {
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Connection')->delete(array('id' => $connection->getId()));
         return array('success' => true, 'message' => 'Connection successful deleted');
     } else {
         throw new StatusCode\NotFoundException('Could not find connection');
     }
 }
示例#11
0
 protected function insertRoutes($scopeId, $routes)
 {
     if (!empty($routes) && is_array($routes)) {
         foreach ($routes as $route) {
             //$this->getFieldValidator()->validate($field);
             if ($route->getAllow()) {
                 $this->tableManager->getTable('Fusio\\Backend\\Table\\Scope\\Route')->create(array('scopeId' => $scopeId, 'routeId' => $route->getRouteId(), 'allow' => $route->getAllow() ? 1 : 0, 'methods' => $route->getMethods()));
             }
         }
     }
 }
示例#12
0
文件: Entity.php 项目: virusvn/fusio
 /**
  * Returns the DELETE response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doDelete(RecordInterface $record, Version $version)
 {
     $routeId = (int) $this->getUriFragment('route_id');
     $route = $this->tableManager->getTable('Fusio\\Backend\\Table\\Routes')->get($routeId);
     if (!empty($route)) {
         $this->tableManager->getTable('Fusio\\Backend\\Table\\Routes')->update(array('id' => $route->getId(), 'status' => 0));
         return array('success' => true, 'message' => 'Routes successful deleted');
     } else {
         throw new StatusCode\NotFoundException('Could not find route');
     }
 }
示例#13
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->create(array('methods' => $record->getMethods(), 'path' => $record->getPath(), 'controller' => 'Fusio\\Impl\\Controller\\SchemaApiController', 'config' => $record->getConfig()));
     // get last insert id
     $routeId = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->getLastInsertId();
     // insert dependency links
     $this->routesDependencyManager->insertDependencyLinks($routeId, $record->getConfig());
     // lock dependencies
     $this->routesDependencyManager->lockExistingDependencies($routeId);
     return array('success' => true, 'message' => 'Route successful created');
 }
示例#14
0
文件: Entity.php 项目: virusvn/fusio
 /**
  * Returns the DELETE response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doDelete(RecordInterface $record, Version $version)
 {
     $schemaId = (int) $this->getUriFragment('schema_id');
     $schema = $this->tableManager->getTable('Fusio\\Backend\\Table\\Schema')->get($schemaId);
     if (!empty($schema)) {
         $this->tableManager->getTable('Fusio\\Backend\\Table\\Schema')->delete(array('id' => $schema['id']));
         return array('success' => true, 'message' => 'Schema successful deleted');
     } else {
         throw new StatusCode\NotFoundException('Could not find schema');
     }
 }
示例#15
0
 protected function saveUserDecision($appId, $allow)
 {
     $condition = new Condition();
     $condition->equals('userId', $this->userId);
     $condition->equals('appId', $appId);
     $table = $this->tableManager->getTable('Fusio\\Impl\\Table\\User\\Grant');
     $userApp = $table->getOneBy($condition);
     if (empty($userApp)) {
         $table->create(['userId' => $this->userId, 'appId' => $appId, 'allow' => $allow ? 1 : 0, 'date' => new \DateTime()]);
     } else {
         $table->update(['id' => $userApp['id'], 'userId' => $this->userId, 'appId' => $appId, 'allow' => $allow ? 1 : 0, 'date' => new \DateTime()]);
     }
 }
示例#16
0
 /**
  * Returns the PUT response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doUpdate(RecordInterface $record, Version $version)
 {
     // we can only change the password through the backend app
     if ($this->appId != 1) {
         throw new StatusCode\BadRequestException('Changing the password is only possible through the backend app');
     }
     // check verify password
     if ($record->getNewPassword() != $record->getVerifyPassword()) {
         throw new StatusCode\BadRequestException('New password does not match the verify password');
     }
     // change password
     $result = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\User')->changePassword($this->userId, $record->getOldPassword(), $record->getNewPassword());
     if ($result) {
         return array('success' => true, 'message' => 'Password successful changed');
     } else {
         throw new StatusCode\BadRequestException('Changing password failed');
     }
 }
示例#17
0
文件: Entity.php 项目: uqiauto/fusio
 /**
  * Returns the DELETE response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doDelete(RecordInterface $record, Version $version)
 {
     $routeId = (int) $this->getUriFragment('route_id');
     $route = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->get($routeId);
     if (!empty($route)) {
         // check whether route has a production version
         if ($this->hasProductionVersion($route->getConfig())) {
             throw new StatusCode\ConflictException('It is not possible to delete a route which contains a production version');
         }
         // remove all dependency links
         $this->routesDependencyManager->removeExistingDependencyLinks($route->getId());
         // unlock dependencies
         $this->routesDependencyManager->unlockExistingDependencies($route->getId());
         // remove all scope routes
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Scope\\Route')->deleteAllFromRoute($route->getId());
         // delete route
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->delete(array('id' => $route->getId()));
         return array('success' => true, 'message' => 'Routes successful deleted');
     } else {
         throw new StatusCode\NotFoundException('Could not find route');
     }
 }
示例#18
0
 public function doNested()
 {
     $this->setBody(array('entry' => $this->tableManager->getTable('PSX\\Sql\\TestTable')->getNestedResult()));
 }
示例#19
0
 protected function getValidator(MethodAbstract $method)
 {
     return new Validator(array(new Property('/id', Validate::TYPE_INTEGER, array(new PrimaryKey($this->tableManager->getTable('Fusio\\Impl\\Table\\Schema'))))));
 }
示例#20
0
 /**
  * Returns the DELETE response
  *
  * @param \PSX\Record\RecordInterface $record
  * @return array|\PSX\Record\RecordInterface
  */
 protected function doDelete($record)
 {
     $this->appGrantService->delete($this->userId, (int) $this->getUriFragment('grant_id'));
 }
示例#21
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Action')->create(array('status' => Action::STATUS_ACTIVE, 'name' => $record->getName(), 'class' => $record->getClass(), 'config' => $record->getConfig()->getRecordInfo()->getData(), 'date' => new \DateTime()));
     return array('success' => true, 'message' => 'Action successful created');
 }
示例#22
0
 public function testGetConnection()
 {
     $manager = new TableManager($this->connection);
     $this->assertInstanceOf('Doctrine\\DBAL\\Connection', $manager->getConnection());
 }
示例#23
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->getValidator()->validate($record);
     $this->tableManager->getTable('Fusio\\Backend\\Table\\Connection')->create(array('name' => $record->getName(), 'class' => $record->getClass(), 'config' => $record->getConfig()->getRecordInfo()->getData()));
     return array('success' => true, 'message' => 'Connection successful created');
 }
示例#24
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->getValidator()->validate($record);
     $this->tableManager->getTable('Fusio\\Backend\\Table\\Routes')->create(array('methods' => $record->getMethods(), 'path' => $record->getPath(), 'controller' => 'Fusio\\Controller\\SchemaApiController', 'config' => $record->getConfig()));
     return array('success' => true, 'message' => 'Route successful created');
 }
示例#25
0
 protected function getValidator(MethodAbstract $method)
 {
     return new Validator(array(new Property('/id', Validate::TYPE_INTEGER, array(new PrimaryKey($this->tableManager->getTable('Fusio\\Impl\\Table\\Routes')))), new Property('/path', Validate::TYPE_STRING, array(new Path())), new Property('/config/(\\d+)/methods/([A-Z]+)/request', Validate::TYPE_INTEGER, array(new PrimaryKey($this->tableManager->getTable('Fusio\\Impl\\Table\\Schema')))), new Property('/config/(\\d+)/methods/([A-Z]+)/response', Validate::TYPE_INTEGER, array(new PrimaryKey($this->tableManager->getTable('Fusio\\Impl\\Table\\Schema')))), new Property('/config/(\\d+)/methods/([A-Z]+)/action', Validate::TYPE_INTEGER, array(new PrimaryKey($this->tableManager->getTable('Fusio\\Impl\\Table\\Action'))))));
 }