You are here

function drd_server_load_user in Drupal Remote Dashboard Server 7

Same name and namespace in other branches
  1. 6 drd_server.module \drd_server_load_user()

Load user for session and check permission.

This function loads the user from the given session ID and checks his/her the permissions to access admin configuration of the site.

Parameters

$sid: The session ID that was returned by drd_server_connect().

Return value

Returns the global user object if session is valid and if permissions are sufficient, an error message otherwise.

See also

drd_server_connect

11 calls to drd_server_load_user()
drd_server_domain_flush_cache in ./drd_server.domain.inc
drd_server_domain_info in ./drd_server.domain.inc
drd_server_domain_list_updates in ./drd_server.domain.inc
drd_server_domain_run_cron in ./drd_server.domain.inc
drd_server_domain_run_update in ./drd_server.domain.inc

... See full list

File

./drd_server.module, line 133

Code

function drd_server_load_user($sid) {
  $account = drd_server_get_account_by_session($sid);
  if (isset($account) && $account && $account->uid > 0) {
    $account = drupal_unpack($account);
    $account->roles = array();
    $account->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
    $account->roles += db_query("SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = :uid", array(
      ':uid' => $account->uid,
    ))
      ->fetchAllKeyed(0, 1);
  }
  else {
    return t('You are not logged in.');
  }
  if (user_access('administer site configuration', $account)) {
    global $user;
    $user = $account;
    return $user;
  }
  return t('You do not have permission to access system data.');
}