This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConglomerateUserResource.php
65 lines (53 loc) · 1.64 KB
/
ConglomerateUserResource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Conglomerate user resource
*
* @Action(name='info', controller='userInfo')
* @Action(name='roleUpdate', controller='roleUpdate')
*/
class ConglomerateUserResource {
/**
* Retrieves information about the current user
*
* @return object
*
* @Access(callback='user_access', args={'access content'}, appendArgs=false)
*/
public static function userInfo() {
global $user;
$data = (array)$user;
unset($data['pass']);
return (object)$data;
}
/**
* Retrieves information about the current user
*
* @param object $info ["data"]
*
* @return object
*
* @Access(callback='user_access', args={'access content'}, appendArgs=false)
*/
public static function roleUpdate($info) {
$return = array('error' => TRUE);
// Extract the info we need from post data
$uid = $info->euid;
$consumer = services_get_server_info('oauth_consumer');
// Get site ID
$result = db_query("SELECT * FROM {conglomerate_source} WHERE oauth_consumer='%s' LIMIT 1", $consumer->key);
if ($result !== FALSE) {
$site = db_fetch_object($result);
$sid = $site->nid;
}
if ($result !== FALSE && $info->roles != NULL) {
// Delete old roles (if any) to avoid duplicates
db_query("DELETE FROM {conglomerate_user_roles} WHERE uid=%d AND sid=%d", $uid, $sid);
// If no roles were sent it means user is deleted. And also, the for loop won't be run.
foreach ($info->roles as $role) {
db_query("INSERT INTO {conglomerate_user_roles} VALUES(%d, '%s', %d)", $uid, $role, $sid);
}
$return = array('error' => FALSE);
}
return (object)$return;
}
}