/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { if (!parent::prepare($args)) { return false; } if (!common_logged_in()) { // TRANS: Client error displayed trying to delete an application while not logged in. $this->clientError(_('You must be logged in to delete an application.')); return false; } $id = (int) $this->arg('id'); $this->app = Oauth_application::staticGet('id', $id); if (empty($this->app)) { // TRANS: Client error displayed trying to delete an application that does not exist. $this->clientError(_('Application not found.')); return false; } $cur = common_current_user(); if ($cur->id != $this->app->owner) { // TRANS: Client error displayed trying to delete an application the current user does not own. $this->clientError(_('You are not the owner of this application.'), 401); return false; } return true; }
/** * Load attributes based on database arguments * * Loads all the DB stuff * * @param array $args $_REQUEST array * * @return success flag */ function prepare($args) { parent::prepare($args); $id = (int) $this->arg('id'); $this->application = Oauth_application::staticGet($id); $this->owner = User::staticGet($this->application->owner); if (!common_logged_in()) { $this->clientError(_('You must be logged in to view an application.')); return false; } if (empty($this->application)) { $this->clientError(_('No such application.'), 404); return false; } $cur = common_current_user(); if ($cur->id != $this->owner->id) { $this->clientError(_('You are not the owner of this application.'), 401); return false; } return true; }
/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { if (!parent::prepare($args)) { return false; } if (!common_logged_in()) { $this->clientError(_('You must be logged in to delete an application.')); return false; } $id = (int) $this->arg('id'); $this->app = Oauth_application::staticGet('id', $id); if (empty($this->app)) { $this->clientError(_('Application not found.')); return false; } $cur = common_current_user(); if ($cur->id != $this->app->owner) { $this->clientError(_('You are not the owner of this application.'), 401); return false; } return true; }
/** * Load attributes based on database arguments * * Loads all the DB stuff * * @param array $args $_REQUEST array * * @return success flag */ function prepare($args) { parent::prepare($args); $id = (int) $this->arg('id'); $this->application = Oauth_application::staticGet($id); $this->owner = User::staticGet($this->application->owner); if (!common_logged_in()) { // TRANS: Client error displayed trying to display an OAuth application while not logged in. $this->clientError(_('You must be logged in to view an application.')); return false; } if (empty($this->application)) { // TRANS: Client error displayed trying to display a non-existing OAuth application. $this->clientError(_('No such application.'), 404); return false; } $cur = common_current_user(); if ($cur->id != $this->owner->id) { // TRANS: Client error displayed trying to display an OAuth application for which the logged in user is not the owner. $this->clientError(_('You are not the owner of this application.'), 401); return false; } return true; }
function showConnection() { $app = Oauth_application::staticGet('id', $this->connection->application_id); $this->out->elementStart('li', array('class' => 'application', 'id' => 'oauthclient-' . $app->id)); $this->out->elementStart('span', 'vcard author'); $this->out->elementStart('a', array('href' => $app->source_url, 'class' => 'url')); if (!empty($app->icon)) { $this->out->element('img', array('src' => $app->icon, 'class' => 'photo avatar')); } if ($app->name != 'anonymous') { $this->out->element('span', 'fn', $app->name); } $this->out->elementEnd('a'); if ($app->name == 'anonymous') { // TRANS: Name for an anonymous application in application list. $this->out->element('span', 'fn', _('Unknown application')); } $this->out->elementEnd('span'); if ($app->name != 'anonymous') { // @todo FIXME: i18n trouble. // TRANS: Message has a leading space and a trailing space. Used in application list. // TRANS: Before this message the application name is put, behind it the organisation that manages it. $this->out->raw(_(' by ')); $this->out->element('a', array('href' => $app->homepage, 'class' => 'url'), $app->organization); } // TRANS: Application access type $readWriteText = _('read-write'); // TRANS: Application access type $readOnlyText = _('read-only'); $access = $this->connection->access_type & Oauth_application::$writeAccess ? $readWriteText : $readOnlyText; $modifiedDate = common_date_string($this->connection->modified); // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only") $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access); // @todo FIXME: i18n trouble. $this->out->raw(" - {$txt}"); if (!empty($app->description)) { $this->out->element('p', array('class' => 'application_description'), $app->description); } $this->out->element('p', array('class' => 'access_token'), sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))); $this->out->elementStart('form', array('id' => 'form_revoke_app', 'class' => 'form_revoke_app', 'method' => 'POST', 'action' => common_local_url('oauthconnectionssettings'))); $this->out->elementStart('fieldset'); $this->out->hidden('oauth_token', $this->connection->token); $this->out->hidden('token', common_session_token()); // TRANS: Button label in application list to revoke access to user data. $this->out->submit('revoke', _m('BUTTON', 'Revoke')); $this->out->elementEnd('fieldset'); $this->out->elementEnd('form'); $this->out->elementEnd('li'); }
/** * Revoke an access token * * XXX: Confirm revoke before doing it * * @param int $appId the ID of the application * */ function revokeAccess($token) { $cur = common_current_user(); $appUser = Oauth_application_user::getByUserAndToken($cur, $token); if (empty($appUser)) { // TRANS: Client error when trying to revoke access for an application while not being a user of it. $this->clientError(_('You are not a user of that application.'), 401); return false; } $app = Oauth_application::staticGet('id', $appUser->application_id); $datastore = new ApiStatusNetOAuthDataStore(); $datastore->revoke_token($appUser->token, 1); $result = $appUser->delete(); if (!$result) { common_log_db_error($orig, 'DELETE', __FILE__); // TRANS: Client error when revoking access has failed for some reason. // TRANS: %s is the application ID revoking access failed for. $this->clientError(sprintf(_('Unable to revoke access for application: %s.'), $app->id)); return false; } $msg = 'API OAuth - user %s (id: %d) revoked access token %s for app id %d'; common_log(LOG_INFO, sprintf($msg, $cur->nickname, $cur->id, $appUser->token, $appUser->application_id)); $msg = sprintf(_('You have successfully revoked access for %1$s and the access token starting with %2$s.'), $app->name, substr($appUser->token, 0, 7)); $this->showForm($msg, true); }
/** * Does the app name already exist? * * Checks the DB to see someone has already registered an app * with the same name. * * @param string $name app name to check * * @return boolean true if the name already exists */ function nameExists($name) { $newapp = Oauth_application::staticGet('name', $name); if (empty($newapp)) { return false; } else { return $newapp->id != $this->app->id; } }
/** * Get the source of the notice * * @return Notice_source $ns A notice source object. 'code' is the only attribute * guaranteed to be populated. */ function getSource() { $ns = new Notice_source(); if (!empty($this->source)) { switch ($this->source) { case 'web': case 'xmpp': case 'mail': case 'omb': case 'system': case 'api': $ns->code = $this->source; break; default: $ns = Notice_source::staticGet($this->source); if (!$ns) { $ns = new Notice_source(); $ns->code = $this->source; $app = Oauth_application::staticGet('name', $this->source); if ($app) { $ns->name = $app->name; $ns->url = $app->source_url; } } break; } } return $ns; }
function sourceLink($source) { $source_name = _($source); switch ($source) { case 'web': case 'xmpp': case 'mail': case 'omb': case 'api': break; default: $name = null; $url = null; $ns = Notice_source::staticGet($source); if ($ns) { $name = $ns->name; $url = $ns->url; } else { $app = Oauth_application::staticGet('name', $source); if ($app) { $name = $app->name; $url = $app->source_url; } } if (!empty($name) && !empty($url)) { $source_name = '<a href="' . $url . '">' . $name . '</a>'; } break; } return $source_name; }
/** * Show the source of the notice * * Either the name (and link) of the API client that posted the notice, * or one of other other channels. * * @return void */ function showNoticeSource() { if ($this->notice->source) { $this->out->text(' '); $this->out->elementStart('span', 'source'); $this->out->text(_('from')); $source_name = _($this->notice->source); $this->out->text(' '); switch ($this->notice->source) { case 'web': case 'xmpp': case 'mail': case 'omb': case 'system': case 'api': $this->out->element('span', 'device', $source_name); break; default: $name = $source_name; $url = null; if (Event::handle('StartNoticeSourceLink', array($this->notice, &$name, &$url, &$title))) { $ns = Notice_source::staticGet($this->notice->source); if ($ns) { $name = $ns->name; $url = $ns->url; } else { $app = Oauth_application::staticGet('name', $this->notice->source); if ($app) { $name = $app->name; $url = $app->source_url; } } } Event::handle('EndNoticeSourceLink', array($this->notice, &$name, &$url, &$title)); if (!empty($name) && !empty($url)) { $this->out->elementStart('span', 'device'); $this->out->element('a', array('href' => $url, 'rel' => 'external', 'title' => $title), $name); $this->out->elementEnd('span'); } else { $this->out->element('span', 'device', $name); } break; } $this->out->elementEnd('span'); } }
/** * Does the app name already exist? * * Checks the DB to see someone has already registered an app * with the same name. * * @param string $name app name to check * * @return boolean true if the name already exists */ function nameExists($name) { $app = Oauth_application::staticGet('name', $name); return !empty($app); }
/** * Revoke access to an authorized OAuth application * * @param int $appId the ID of the application * */ function revokeAccess($appId) { $cur = common_current_user(); $app = Oauth_application::staticGet('id', $appId); if (empty($app)) { $this->clientError(_('No such application.'), 404); return false; } // XXX: Transaction here? $appUser = Oauth_application_user::getByKeys($cur, $app); if (empty($appUser)) { $this->clientError(_('You are not a user of that application.'), 401); return false; } $datastore = new ApiStatusNetOAuthDataStore(); $datastore->revoke_token($appUser->token, 1); $result = $appUser->delete(); if (!$result) { common_log_db_error($orig, 'DELETE', __FILE__); $this->clientError(sprintf(_('Unable to revoke access for app: %s.'), $app->id)); return false; } $msg = 'User %s (id: %d) revoked access to app %s (id: %d)'; common_log(LOG_INFO, sprintf($msg, $cur->nickname, $cur->id, $app->name, $app->id)); }