diff --git a/lib/classes/API/OAuth2/AuthCode.php b/lib/classes/API/OAuth2/AuthCode.php deleted file mode 100644 index a9773968a5..0000000000 --- a/lib/classes/API/OAuth2/AuthCode.php +++ /dev/null @@ -1,180 +0,0 @@ -app = $app; - $this->code = $code; - $sql = 'SELECT code, api_account_id, redirect_uri, UNIX_TIMESTAMP(expires) AS expires, scope - FROM api_oauth_codes WHERE code = :code'; - - $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); - $stmt->execute([':code' => $this->code]); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ( ! $row) - throw new NotFoundHttpException('Code not found'); - - $this->account_id = (int) $row['api_account_id']; - $this->redirect_uri = $row['redirect_uri']; - $this->expires = $row['expires']; - $this->scope = $row['scope']; - - return $this; - } - - public function get_code() - { - return $this->code; - } - - /** - * - * @return API_OAuth2_Account - */ - public function get_account() - { - if ( ! $this->account) - $this->account = new API_OAuth2_Account($this->app, $this->account_id); - - return $this->account; - } - - public function get_redirect_uri() - { - return $this->redirect_uri; - } - - public function set_redirect_uri($redirect_uri) - { - $sql = 'UPDATE api_oauth_codes SET redirect_uri = :redirect_uri - WHERE code = :code'; - - $params = [':redirect_uri' => $redirect_uri, ':code' => $this->code]; - - $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - $this->redirect_uri = $redirect_uri; - - return $this; - } - - /** - * - * @return int - */ - public function get_expires() - { - return $this->expires; - } - - public function get_scope() - { - return $this->scope; - } - - public function set_scope($scope) - { - $sql = 'UPDATE api_oauth_codes SET scope = :scope - WHERE code = :code'; - - $params = [':scope' => $scope, ':code' => $this->code]; - - $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - $this->scope = $scope; - - return $this; - } - - public function delete() - { - $sql = 'DELETE FROM api_oauth_codes WHERE code = :code'; - - $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); - $stmt->execute([':code' => $this->code]); - $stmt->closeCursor(); - - return; - } - - /** - * - * @param Application $app - * @param API_OAuth2_Account $account - * @return array - */ - public static function load_codes_by_account(Application $app, API_OAuth2_Account $account) - { - $sql = 'SELECT code FROM api_oauth_codes - WHERE api_account_id = :account_id'; - - $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); - - $params = [":account_id" => $account->get_id()]; - $stmt->execute($params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $codes = []; - - foreach ($rs as $row) { - $codes[] = new API_OAuth2_AuthCode($app, $row['code']); - } - - return $codes; - } - - /** - * - * @param Application $app - * @param API_OAuth2_Account $account - * @param type $code - * @param int $expires - * @return API_OAuth2_AuthCode - */ - public static function create(Application $app, API_OAuth2_Account $account, $code, $expires) - { - - $sql = 'INSERT INTO api_oauth_codes (code, api_account_id, expires) - VALUES (:code, :account_id, FROM_UNIXTIME(:expires))'; - - $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); - - $params = [ - ":code" => $code, - ":account_id" => $account->get_id(), - ":expires" => $expires - ]; - $stmt->execute($params); - $stmt->closeCursor(); - - return new self($app, $code); - } -}