function showConnection()
 {
     $app = Oauth_application::getKV('id', $this->connection->application_id);
     $this->out->elementStart('li', array('class' => 'application h-entry', 'id' => 'oauthclient-' . $app->id));
     $this->out->elementStart('a', array('href' => $app->source_url, 'class' => 'h-card p-name'));
     if (!empty($app->icon)) {
         $this->out->element('img', array('src' => $app->icon, 'class' => 'avatar u-photo'));
     }
     if ($app->name != 'anonymous') {
         $this->out->text($app->name);
     } else {
         // TRANS: Name for an anonymous application in application list.
         $this->out->element('span', 'p-name', _('Unknown application'));
     }
     $this->out->elementEnd('a');
     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' => 'h-card'), $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');
 }
 /**
  * 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::getKV($id);
     $this->owner = User::getKV($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.'));
     }
     if (empty($this->application)) {
         // TRANS: Client error displayed trying to display a non-existing OAuth application.
         $this->clientError(_('No such application.'), 404);
     }
     $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 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()) {
         // TRANS: Client error displayed trying to delete an application while not logged in.
         $this->clientError(_('You must be logged in to delete an application.'));
     }
     $id = (int) $this->arg('id');
     $this->app = Oauth_application::getKV('id', $id);
     if (empty($this->app)) {
         // TRANS: Client error displayed trying to delete an application that does not exist.
         $this->clientError(_('Application not found.'));
     }
     $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 true;
 }
Beispiel #4
0
 /**
  * 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()
 {
     if (empty($this->source)) {
         return false;
     }
     $ns = new Notice_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::getKV($this->source);
             if (!$ns) {
                 $ns = new Notice_source();
                 $ns->code = $this->source;
                 $app = Oauth_application::getKV('name', $this->source);
                 if ($app) {
                     $ns->name = $app->name;
                     $ns->url = $app->source_url;
                 }
             }
             break;
     }
     return $ns;
 }
 /**
  * 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);
     }
     $app = Oauth_application::getKV('id', $appUser->application_id);
     $datastore = new ApiGNUsocialOAuthDataStore();
     $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));
     }
     $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)
 {
     $app = Oauth_application::getKV('name', $name);
     return !empty($app);
 }
 /**
  * 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::getKV('name', $name);
     if (empty($newapp)) {
         return false;
     } else {
         return $newapp->id != $this->app->id;
     }
 }