You are here

function drupalchat_user in DrupalChat 6.2

Same name and namespace in other branches
  1. 6 drupalchat.module \drupalchat_user()

Implementation of hook_user()

File

./drupalchat.module, line 340
Module code for DrupalChat.

Code

function drupalchat_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'login':
      setcookie("DRUPALCHAT_NEWLOGIN", 1, time() + 120, '/');
      if (variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX) == DRUPALCHAT_COMMERCIAL) {
        setcookie("iflychat_key", "", time() - 3600, "/");
        setcookie("iflychat_css", "", time() - 3600, "/");
        setcookie("iflychat_time", "", time() - 3600, "/");
      }
      db_query('DELETE FROM {drupalchat_msg} WHERE uid1 = uid2 AND uid1 = %d', $account->uid);
      break;
    case 'logout':
      if (variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX) == DRUPALCHAT_COMMERCIAL) {
        setcookie("iflychat_key", "", time() - 3600, "/");
        setcookie("iflychat_css", "", time() - 3600, "/");
        setcookie("iflychat_time", "", time() - 3600, "/");
      }

      //delete token
      $data = json_encode(array(
        'api_key' => variable_get('drupalchat_external_api_key', NULL),
      ));
      $result = drupal_http_request('https://api.iflychat.com/api/1.1/token/' . $_SESSION['token'] . '/delete', array(
        'Content-Type' => 'application/json',
      ), 'POST', $data, 15);
      unset($_SESSION['token']);
      break;
  }
}