Skip to content

Commit 5af5cc6

Browse files
author
Mateu Aguiló Bosch
committed
Merge branch '7.x-1.x' of git.drupal.org:project/restful into 7.x-1.x
2 parents 572046e + 7420a34 commit 5af5cc6

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

modules/restful_token_auth/restful_token_auth.module

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,24 @@ function restful_token_auth_cron() {
131131
$ids = array_keys($result['restful_token_auth']);
132132
entity_delete_multiple('restful_token_auth', $ids);
133133
}
134+
135+
/**
136+
* Implements hook_user_update().
137+
*/
138+
function restful_token_auth_user_update(&$edit, $account, $category) {
139+
if ($edit['status']) {
140+
return;
141+
}
142+
143+
$query = new EntityFieldQuery();
144+
$result = $query
145+
->entityCondition('entity_type', 'restful_token_auth')
146+
->propertyCondition('uid', $account->uid)
147+
->execute();
148+
149+
if (empty($result['restful_token_auth'])) {
150+
return;
151+
}
152+
153+
entity_delete_multiple('restful_token_auth', array_keys($result['restful_token_auth']));
154+
}

modules/restful_token_auth/tests/RestfulTokenAuthenticationTestCase.test

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,50 @@ class RestfulTokenAuthenticationTestCase extends DrupalWebTestCase {
1717

1818
function setUp() {
1919
parent::setUp('restful_example', 'restful_token_auth', 'entityreference');
20+
21+
$this->user = $this->drupalCreateUser();
22+
}
23+
24+
/**
25+
* Testing the user's access token will be invalidate one the user is blocked.
26+
*/
27+
function testTokenInvalidating() {
28+
$this->drupalLogin($this->user);
29+
$handler = restful_get_restful_handler('access_token');
30+
31+
// Generating token.
32+
$handler->get();
33+
34+
// Blocking the user.
35+
user_save($this->user, array('status' => FALSE));
36+
37+
// Verify the token removed.
38+
$query = new EntityFieldQuery();
39+
$result = $query
40+
->entityCondition('entity_type', 'restful_token_auth')
41+
->propertyCondition('uid', $this->user->uid)
42+
->execute();
43+
44+
$this->assertTrue(empty($result), 'The access tokens invalidated when blocking the user.');
2045
}
2146

2247
/**
2348
* Test authenticating a user.
2449
*/
2550
function testAuthentication() {
2651
// Create user.
27-
$user1 = $this->drupalCreateUser();
28-
$this->drupalLogin($user1);
52+
$this->user = $this->drupalCreateUser();
53+
$this->drupalLogin($this->user);
2954

3055
// Create "Article" node.
3156
$title1 = $this->randomName();
3257
$settings = array(
3358
'type' => 'article',
3459
'title' => $title1,
35-
'uid' => $user1->uid,
60+
'uid' => $this->user->uid,
3661
);
3762
$node1 = $this->drupalCreateNode($settings);
38-
$id= $node1->nid;
63+
$id = $node1->nid;
3964

4065
// Get a token for the user, using the handler.
4166
$handler = restful_get_restful_handler('access_token');

plugins/authentication/RestfulAuthenticationManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ public function getAccount(array $request = array(), $method = \RestfulInterface
8787
// Resolve the user based on the providers in the manager.
8888
$account = NULL;
8989
foreach ($this as $provider) {
90-
if ($provider->applies($request, $method) && $account = $provider->authenticate($request, $method)) {
90+
if ($provider->applies($request) && ($account = $provider->authenticate($request)) && $account->uid && $account->status) {
9191
// The account has been loaded, we can stop looking.
9292
break;
9393
}
9494
}
9595

96-
if (!$account) {
96+
if (empty($account->uid) || !$account->status) {
9797

9898
if ($this->count() && !$this->getIsOptional()) {
9999
// Allow caching pages for anonymous users.

0 commit comments

Comments
 (0)