You are here

private function LingotekSession::login in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 6 lingotek.session.inc \LingotekSession::login()
  2. 7.2 lingotek.session.inc \LingotekSession::login()
  3. 7.3 lingotek.session.inc \LingotekSession::login()
  4. 7.4 lingotek.session.inc \LingotekSession::login()
  5. 7.5 lingotek.session.inc \LingotekSession::login()
  6. 7.6 lingotek.session.inc \LingotekSession::login()
2 calls to LingotekSession::login()
LingotekSession::canLogIn in ./lingotek.session.inc
LingotekSession::request in ./lingotek.session.inc

File

./lingotek.session.inc, line 233
Handles api calls, logging in and logging out of LingoTek

Class

LingotekSession

Code

private function login() {
  if ($this->key == "") {
    $params = array(
      'loginId' => $this->login_id,
      'password' => $this->password,
      'community' => $this->community,
    );
    $login = 'login';
  }
  $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") {
      if (!empty($response->error)) {
        $error = $response->error;
      }
      else {
        $error = t('Make sure your password is compatible with single sign on. Visit https://sso.lingotek.com/login.');
      }
    }
  }
  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 into: " . $this->url, array(
      'params' => $params,
      'error' => $error,
      'response' => json_encode($response),
    ), 'session');
  }
}