function _drupalchat_get_auth in DrupalChat 6.2
Same name and namespace in other branches
- 7.2 drupalchat.module \_drupalchat_get_auth()
- 7 drupalchat.module \_drupalchat_get_auth()
3 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_settings_form_validate in ./drupalchat.admin.inc
File
- ./drupalchat.module, line 984
- Module code for DrupalChat.
Code
function _drupalchat_get_auth($name, $formValues) {
global $user, $base_url;
$theme = variable_get('drupalchat_theme', 'light');
if (user_access('administer drupalchat')) {
$role = "admin";
}
else {
$role = $user->roles;
}
if (array_key_exists('api_key', $formValues)) {
$api_key = $formValues['api_key'];
}
else {
$api_key = variable_get('drupalchat_external_api_key', NULL);
}
if (array_key_exists('app_id', $formValues)) {
$app_id = $formValues['app_id'];
}
else {
$app_id = variable_get('drupalchat_app_id', NULL);
}
if ($user->uid) {
$data = array(
'user_name' => $name,
'user_id' => $user->uid,
'api_key' => $api_key,
'app_id' => $app_id,
'user_roles' => $role,
'version' => 'D6',
'user_status' => TRUE,
'user_list_filter' => 'all',
);
}
$data['user_avatar_url'] = drupalchat_return_pic_url();
$data['user_profile_url'] = drupalchat_return_profile_url();
if (variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH) > DRUPALCHAT_REL_AUTH) {
$data['user_list_filter'] = 'friend';
$new_valid_uids = _drupalchat_get_buddylist($user->uid);
if (!isset($_SESSION['drupalchat_user_roster_list']) || $_SESSION['drupalchat_user_roster_list'] != $new_valid_uids) {
$data['user_relationships'] = $new_valid_uids;
$_SESSION['drupalchat_user_roster_list'] = $new_valid_uids;
}
else {
$data['user_relationships'] = $new_valid_uids;
}
}
$data = json_encode($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', array(
'Content-Type' => 'application/json',
), 'POST', $data, 15);
if ($result->code == 200) {
$result = json_decode($result->data);
if ($user->uid) {
$_SESSION['token'] = $result->key;
}
if (array_key_exists('app_id', $result)) {
variable_set('drupalchat_app_id', $result->app_id);
}
return $result;
}
else {
return $result;
}
}