You are here

function DrupalSalesforce::login in Salesforce Suite 7

Same name and namespace in other branches
  1. 5.2 salesforce_api/salesforce.class.inc \DrupalSalesforce::login()

Establishes a connection and logs in to the Salesforce server.

Return value

TRUE or FALSE indicating the success of the login.

File

salesforce_api/salesforce.class.inc, line 51
Defines the class used for communicating with the Salesforce server.

Class

DrupalSalesforce

Code

function login() {

  // Default to the WSDL downloaded from the user account if available.
  $wsdl = SALESFORCE_DIR_WSDL . '/enterprise.wsdl.xml';

  // Otherwise fall back to the one included with the Toolkit.
  if (!file_exists($wsdl)) {
    $wsdl = SALESFORCE_DIR_SOAPCLIENT . '/enterprise.wsdl.xml';
  }

  // Connect to the server and login, logging any failures to the watchdog.
  try {

    // Connect to the server.
    $this->client
      ->createConnection($wsdl);

    // Attempt a login with the credentials entered by the user.
    $this->login = $this->client
      ->login($this->username, $this->password . $this->token);

    // Log the login occurence.
    $this
      ->watchdog(SALESFORCE_LOG_ALL, '@user (@email) logged into Salesforce.', array(
      '@user' => $this->login->userInfo->userFullName,
      '@email' => $this->login->userInfo->userEmail,
    ));
  } catch (Exception $e) {

    // Log the error message.
    $this
      ->watchdog(SALESFORCE_LOG_SOME, 'Could not login to Salesforce: %message. <pre>!debug</pre>', array(
      '%message' => $e->faultstring,
      '!debug' => check_plain($this->client
        ->getLastRequest()),
    ), WATCHDOG_ERROR);

    // Indicate the failed login.
    return FALSE;
  }

  // Indicate the successful login.
  return TRUE;
}