You are here

function DrupalSalesforce::login in Salesforce Suite 5.2

Same name and namespace in other branches
  1. 7 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
Defines the DrupalSalesforce class used to interact with the server.

Code

function login() {

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

  // 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.
    $login = $this->client
      ->login($this->username, $this->password . $this->token);

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

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

    // Indicate the failed login.
    return FALSE;
  }

  // Indicate the successful login.
  return TRUE;
}