You are here

function nodejs_auth_check in Node.js integration 7

Same name and namespace in other branches
  1. 8 nodejs.module \nodejs_auth_check()
  2. 6 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 588

Code

function nodejs_auth_check($message) {
  $nodejs_auth_check_callback = variable_get('nodejs_auth_check_callback', 'nodejs_auth_check_callback');
  if (!function_exists($nodejs_auth_check_callback)) {
    throw new Exception("No nodejs_auth_check callback found - looked for '{$nodejs_auth_check_callback}'.");
  }
  $uid = $nodejs_auth_check_callback($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_add_http_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;
}