function salesforce_api_reset_expired_password in Salesforce Suite 7.2
Same name and namespace in other branches
- 6.2 salesforce_api/salesforce_api.module \salesforce_api_reset_expired_password()
- 7 salesforce_api/salesforce_api.module \salesforce_api_reset_expired_password()
Helper function for salesforce_api_connect() to reset an expired password, for the website's default salesforce user only.
Parameters
$sf: The Salesforce client object with an expired password.
Return value
void
1 call to salesforce_api_reset_expired_password()
- salesforce_api_connect in salesforce_api/
salesforce_api.module - Creates an object used for communicating with the Salesforce server and performs a login to verify the API credentials.
File
- salesforce_api/
salesforce_api.module, line 569 - Defines an API that enables modules to interact with the Salesforce server.
Code
function salesforce_api_reset_expired_password($sf) {
// Append one letter and one digit to the password to make sure we meet
// salesforce's password validation requirements.
$new_password = user_password() . 'z9';
// setPassword() may throw InvalidIdFault or UnexpectedErrorFault exceptions.
// @todo: If it may throw exceptions, should it be wrapped in a try/catch block?
$sf->client
->setPassword($sf->login->userId, $new_password);
variable_set('salesforce_api_password', $new_password);
// Salesforce changes the security token when the password gets changed and
// sends an email with the new security token. The new security token can
// not be retrieved via the API.
variable_del('salesforce_api_token');
// Log the event and alert admins about required steps to complete.
$vars = array(
'%user' => $sf->login->userInfo->userFullName,
'%email' => $sf->login->userInfo->userEmail,
'!uri' => url(SALESFORCE_PATH_ADMIN, array(
'absolute' => TRUE,
)),
);
salesforce_api_log(SALESFORCE_LOG_ALL, 'The password for the salesforce
account %user expired. Drupal changed it and saved the new password.
Salesforce updated the security token and emailed it to %email.', $vars);
salesforce_api_log(SALESFORCE_LOG_SOME, 'Provide the new security token
at <a href="!uri">Drupal\'s Salesforce settings page</a>. Salesforce
emailed it to %email.', $vars, WATCHDOG_ALERT);
// If salesforce connects on pages for anonymous users then these messages should not be displayed.
if (user_access('administer salesforce')) {
drupal_set_message(t('The password for the salesforce account %user expired.
Drupal changed it and saved the new password. Salesforce updated the
security token and emailed it to %email.', $vars));
drupal_set_message(t('Provide the new security token at
<a href="!uri">Drupal\'s Salesforce settings page</a>.
Salesforce emailed it to %email.', $vars), 'error');
}
}