You are here

function _drupalchat_get_auth in DrupalChat 7.2

Same name and namespace in other branches
  1. 6.2 drupalchat.module \_drupalchat_get_auth()
  2. 7 drupalchat.module \_drupalchat_get_auth()
4 calls to _drupalchat_get_auth()
drupalchat_app_settings in ./drupalchat.admin.inc
@file Administrative functions to configure DrupalChat.
drupalchat_ex_auth in ./drupalchat.module
drupalchat_mobile_auth in ./drupalchat.mobileauth.inc
drupalchat_settings_form_validate in ./drupalchat.admin.inc
@todo Please document this function.

File

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

Code

function _drupalchat_get_auth($formValues) {
  global $user;
  if (array_key_exists('api_key', $formValues)) {
    $api_key = $formValues['api_key'];
  }
  else {
    $api_key = check_plain(variable_get('drupalchat_external_api_key', NULL));
  }
  if (array_key_exists('app_id', $formValues)) {
    $app_id = $formValues['app_id'];
  }
  else {
    $app_id = check_plain(variable_get('drupalchat_app_id', NULL));
  }
  $data = array(
    'api_key' => $api_key,
    'app_id' => $app_id,
    'version' => 'D7-7.2.2',
  );
  $user_data = _drupalchat_get_user_details();
  $data = array_merge($data, $user_data);
  $data = json_encode($data);
  $_SESSION['user_data'] = json_encode($user_data);

  //print_r($data);
  $options = array(
    'method' => 'POST',
    'data' => $data,
    'timeout' => 15,
    'headers' => array(
      'Content-Type' => 'application/json',
    ),
  );
  $result = drupal_http_request(DRUPALCHAT_EXTERNAL_A_HOST . ':' . DRUPALCHAT_EXTERNAL_A_PORT . '/api/1.1/token/generate', $options);
  if ($result->code == 200) {
    $result = drupal_json_decode($result->data);
    if (user_is_logged_in()) {
      $_SESSION['token'] = $result['key'];
    }
    if (array_key_exists('app_id', $result)) {
      variable_set('drupalchat_app_id', $result['app_id']);
    }
    return $result;
  }
  else {
    return $result;
  }
}