summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-02-05 03:19:12 +0000
committerZach Copley <zach@status.net>2010-02-05 03:19:12 +0000
commit23802e58d6d01e5f8dacade2161147d31b2dacb9 (patch)
tree707120cc8d2d0217e4168473b7a7ef25e94919e0 /lib
parent4502bea9a86fe5992eb9b359d90f0c1f004998c1 (diff)
parent857494c9c61d872b7decf69de226bba6cd250d99 (diff)
Merge branch 'temp'
Diffstat (limited to 'lib')
-rw-r--r--lib/api.php19
-rw-r--r--lib/apiauth.php19
-rw-r--r--lib/apioauthstore.php27
-rw-r--r--lib/noticelist.php20
-rw-r--r--lib/oauthstore.php3
-rw-r--r--lib/router.php4
6 files changed, 76 insertions, 16 deletions
diff --git a/lib/api.php b/lib/api.php
index 10a2fae28..f81975216 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -1249,10 +1249,27 @@ class ApiAction extends Action
case 'api':
break;
default:
+
+ $name = null;
+ $url = null;
+
$ns = Notice_source::staticGet($source);
+
if ($ns) {
- $source_name = '<a href="' . $ns->url . '">' . $ns->name . '</a>';
+ $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;
diff --git a/lib/apiauth.php b/lib/apiauth.php
index 99500404f..25e2196cf 100644
--- a/lib/apiauth.php
+++ b/lib/apiauth.php
@@ -55,6 +55,7 @@ class ApiAuthAction extends ApiAction
{
var $auth_user_nickname = null;
var $auth_user_password = null;
+ var $oauth_source = null;
/**
* Take arguments for running, looks for an OAuth request,
@@ -73,20 +74,18 @@ class ApiAuthAction extends ApiAction
// NOTE: $this->auth_user has to get set in prepare(), not handle(),
// because subclasses do stuff with it in their prepares.
- if ($this->requiresAuth()) {
+ $oauthReq = $this->getOAuthRequest();
- $oauthReq = $this->getOAuthRequest();
-
- if (!$oauthReq) {
+ if (!$oauthReq) {
+ if ($this->requiresAuth()) {
$this->checkBasicAuthUser(true);
} else {
- $this->checkOAuthRequest($oauthReq);
+ // Check to see if a basic auth user is there even
+ // if one's not required
+ $this->checkBasicAuthUser(false);
}
} else {
-
- // Check to see if a basic auth user is there even
- // if one's not required
- $this->checkBasicAuthUser(false);
+ $this->checkOAuthRequest($oauthReq);
}
// Reject API calls with the wrong access level
@@ -108,7 +107,6 @@ class ApiAuthAction extends ApiAction
* This is to avoid doign any unnecessary DB lookups.
*
* @return mixed the OAuthRequest or false
- *
*/
function getOAuthRequest()
@@ -137,7 +135,6 @@ class ApiAuthAction extends ApiAction
* @param OAuthRequest $request the OAuth Request
*
* @return nothing
- *
*/
function checkOAuthRequest($request)
diff --git a/lib/apioauthstore.php b/lib/apioauthstore.php
index 32110d057..1bb11cbca 100644
--- a/lib/apioauthstore.php
+++ b/lib/apioauthstore.php
@@ -159,5 +159,32 @@ class ApiStatusNetOAuthDataStore extends StatusNetOAuthDataStore
}
}
+ /**
+ * Revoke specified access token
+ *
+ * Revokes the token specified by $token_key.
+ * Throws exceptions in case of error.
+ *
+ * @param string $token_key the token to be revoked
+ * @param int $type type of token (0 = req, 1 = access)
+ *
+ * @access public
+ *
+ * @return void
+ */
+
+ public function revoke_token($token_key, $type = 0) {
+ $rt = new Token();
+ $rt->tok = $token_key;
+ $rt->type = $type;
+ $rt->state = 0;
+ if (!$rt->find(true)) {
+ throw new Exception('Tried to revoke unknown token');
+ }
+ if (!$rt->delete()) {
+ throw new Exception('Failed to delete revoked token');
+ }
+ }
+
}
diff --git a/lib/noticelist.php b/lib/noticelist.php
index 85c169716..a4a0f2651 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -486,12 +486,28 @@ class NoticeListItem extends Widget
$this->out->element('span', 'device', $source_name);
break;
default:
+
+ $name = null;
+ $url = null;
+
$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;
+ }
+ }
+
+ if (!empty($name) && !empty($url)) {
$this->out->elementStart('span', 'device');
- $this->out->element('a', array('href' => $ns->url,
+ $this->out->element('a', array('href' => $url,
'rel' => 'external'),
- $ns->name);
+ $name);
$this->out->elementEnd('span');
} else {
$this->out->element('span', 'device', $source_name);
diff --git a/lib/oauthstore.php b/lib/oauthstore.php
index b30fb49d5..eabe37f9f 100644
--- a/lib/oauthstore.php
+++ b/lib/oauthstore.php
@@ -65,7 +65,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
{
$n = new Nonce();
$n->consumer_key = $consumer->key;
- $n->ts = $timestamp;
+ $n->ts = common_sql_date($timestamp);
$n->nonce = $nonce;
if ($n->find(true)) {
return true;
@@ -362,7 +362,6 @@ class StatusNetOAuthDataStore extends OAuthDataStore
array('is_local' => Notice::REMOTE_OMB,
'uri' => $omb_notice->getIdentifierURI()));
-
}
/**
diff --git a/lib/router.php b/lib/router.php
index 4b5b8d0bb..5981ef5d7 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -152,6 +152,10 @@ class Router
array('action' => 'editapplication'),
array('id' => '[0-9]+')
);
+ $m->connect('settings/oauthapps/delete/:id',
+ array('action' => 'deleteapplication'),
+ array('id' => '[0-9]+')
+ );
// search