function clients_connection_drupal_services_rest_7::userLogin in Web Service Clients 7.3
Log in as the configured user.
This requires the server type 'application/x-www-form-urlencoded' to be enabled.
Parameters
$session_id: A session ID obtained from calling system.connect.
Return value
The full data returned from the remote call.
1 call to clients_connection_drupal_services_rest_7::userLogin()
- clients_connection_drupal_services_rest_7::makeRequest in connections/
clients_drupal_rest/ clients_drupal_rest.inc - Make a REST request.
File
- connections/
clients_drupal_rest/ clients_drupal_rest.inc, line 115 - Contains classes for Client connections handlers.
Class
- clients_connection_drupal_services_rest_7
- Class for Drupal client connections, REST D7.
Code
function userLogin() {
// Based on example code at http://drupal.org/node/910598.
$this
->credentialsLoad();
$data = array(
'username' => $this->credentials['username'],
'password' => $this->credentials['password'],
);
$data = http_build_query($data, '', '&');
$headers = array(
'Accept' => 'application/json',
);
$options = array(
'headers' => $headers,
'method' => 'POST',
'data' => $data,
);
$response = drupal_http_request($this->endpoint . '/user/login', $options);
// Check if login was successful.
$this
->handleRestError($response);
$data = json_decode($response->data);
// It's possible for the response to have a 200, but the data to be
// malformed. This happens for example when the remote site is running a
// debugger.
if (!is_object($data) || json_last_error() != JSON_ERROR_NONE) {
throw new Exception(t("Clients connection error logging in. Data received was: '@data'.", array(
'@data' => $response->data,
)), $response->code);
}
// Set our cookie for subsequent requests.
$this->cookie = $data->session_name . '=' . $data->sessid;
return $data;
}