示例#1
0
 public function create($userId, $name, $url, array $scopes = null)
 {
     // validate data
     $this->assertName($name);
     $this->assertUrl($url);
     // check limit of apps which an user can create
     $condition = new Condition();
     $condition->equals('userId', $userId);
     $condition->in('status', [Table\App::STATUS_ACTIVE, Table\App::STATUS_PENDING, Table\App::STATUS_DEACTIVATED]);
     if ($this->appTable->getCount($condition) > $this->appCount) {
         throw new StatusCode\BadRequestException('Maximal amount of apps reached. Please delete another app in order to register a new one');
     }
     $scopes = $this->getValidUserScopes($userId, $scopes);
     if (empty($scopes)) {
         throw new StatusCode\BadRequestException('Provide at least one valid scope for the app');
     }
     $this->appService->create($userId, $this->appApproval === false ? Table\App::STATUS_ACTIVE : Table\App::STATUS_PENDING, $name, $url, null, $scopes);
 }
示例#2
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Record\RecordInterface $record
  * @return array|\PSX\Record\RecordInterface
  */
 protected function doPost($record)
 {
     $this->appService->create($record->userId, $record->status, $record->name, $record->url, $record->parameters, $record->scopes);
     return array('success' => true, 'message' => 'App successful created');
 }