You are here

function nodejs_auth_check in Node.js integration 6

Same name and namespace in other branches
  1. 8 nodejs.module \nodejs_auth_check()
  2. 7 nodejs.module \nodejs_auth_check()

Checks the given key to see if it matches a valid session.

1 call to nodejs_auth_check()
nodejs_message_handler in ./nodejs.module
Menu callback: handles all messages from Node.js server.

File

./nodejs.module, line 443

Code

function nodejs_auth_check($message) {
  $uid = db_result(db_query("SELECT uid FROM {sessions} WHERE MD5(sid) = '%s'", $message['authToken']));
  $auth_user = $uid > 0 ? user_load($uid) : drupal_anonymous_user();
  $auth_user->authToken = $message['authToken'];
  $auth_user->nodejsValidAuthToken = $uid !== FALSE;
  $auth_user->clientId = $message['clientId'];
  if ($auth_user->nodejsValidAuthToken) {

    // Get the list of channels I have access to.
    $auth_user->channels = array();
    foreach (module_implements('nodejs_user_channels') as $module) {
      $function = $module . '_nodejs_user_channels';
      foreach ($function($auth_user) as $channel) {
        $auth_user->channels[] = $channel;
      }
    }

    // Get the list of users who can see presence notifications about me.
    $auth_user->presenceUids = array_unique(module_invoke_all('nodejs_user_presence_list', $auth_user));
    $nodejs_config = nodejs_get_config();
    $auth_user->serviceKey = $nodejs_config['serviceKey'];
    drupal_set_header('NodejsServiceKey: ' . $nodejs_config['serviceKey']);
    drupal_alter('nodejs_auth_user', $auth_user);
    if ($auth_user->uid) {
      nodejs_user_set_online($auth_user->uid);
    }
    $auth_user->contentTokens = isset($message['contentTokens']) ? $message['contentTokens'] : array();
  }
  return $auth_user;
}