private function LingotekSession::login in Lingotek Translation 7.4
Same name and namespace in other branches
- 6 lingotek.session.inc \LingotekSession::login()
- 7.7 lingotek.session.inc \LingotekSession::login()
- 7.2 lingotek.session.inc \LingotekSession::login()
- 7.3 lingotek.session.inc \LingotekSession::login()
- 7.5 lingotek.session.inc \LingotekSession::login()
- 7.6 lingotek.session.inc \LingotekSession::login()
2 calls to LingotekSession::login()
File
- ./
lingotek.session.inc, line 238 - Handles api calls, logging in and logging out of LingoTek
Class
Code
private function login($version = "3.11", $xml = FALSE) {
if ($this->key == "") {
$params = array(
'userLogin' => $this->login_id,
'password' => $this->password,
'version' => $version,
'community' => $this->community,
);
$login = 'login';
}
else {
$arr = array(
'community' => $this->community,
'login_id' => $this->login_id,
'time' => time(),
);
$json_str = json_encode($arr);
$params = array(
"auth_json" => $json_str,
"hmac" => LingotekSession::create_mac($json_str),
"version" => $version,
"returnXML" => $xml,
);
$login = 'keyLogin';
}
$error = 'unknown error';
$success = FALSE;
$response = array();
$data = $this
->request($login, $params, NULL, FALSE);
if (isset($data->data)) {
$response = json_decode($data->data);
if (isset($response->results) && $response->results == "success") {
$success = TRUE;
$error = '';
}
elseif (isset($response->results) && $response->results == "fail") {
$error = $response->error;
}
}
elseif (isset($data->error)) {
$error = $data->error;
}
if ($success) {
$this->headers = array(
"Cookie" => $data->headers['set-cookie'],
);
$this->logged_in = TRUE;
$this->last_login_msg = '';
}
else {
$this->logged_in = FALSE;
$this->last_login_msg = $error;
LingotekLog::error("Unable to log in", array(
'params' => $params,
'error' => $error,
'response' => json_encode($response),
), 'session');
}
}