You are here

protected function LoginValidatorBase::fixOutdatedEmailAddress in Lightweight Directory Access Protocol (LDAP) 8.4

Update an outdated email address.

2 calls to LoginValidatorBase::fixOutdatedEmailAddress()
LoginValidatorLoginForm::processLogin in ldap_authentication/src/Controller/LoginValidatorLoginForm.php
Perform the actual logging in.
LoginValidatorSso::processLogin in ldap_authentication/src/Controller/LoginValidatorSso.php
Perform the actual logging in.

File

ldap_authentication/src/Controller/LoginValidatorBase.php, line 590

Class

LoginValidatorBase
Handles the actual testing of credentials and authentication of users.

Namespace

Drupal\ldap_authentication\Controller

Code

protected function fixOutdatedEmailAddress() : void {
  if ($this->config
    ->get('emailTemplateUsageNeverUpdate') && $this->emailTemplateUsed) {
    return;
  }
  if (!$this->drupalUser) {
    return;
  }
  if ($this->drupalUser
    ->get('mail')->value === $this->serverDrupalUser
    ->deriveEmailFromLdapResponse($this->ldapEntry)) {
    return;
  }
  $update_type = $this->config
    ->get('emailUpdate');
  if (in_array($update_type, [
    'update_notify',
    'update',
  ], TRUE)) {
    $this->drupalUser
      ->set('mail', $this->serverDrupalUser
      ->deriveEmailFromLdapResponse($this->ldapEntry));
    if (!$this->drupalUser
      ->save()) {
      $this->logger
        ->error('Failed to make changes to user %username updated %changed.', [
        '%username' => $this->drupalUser
          ->getAccountName(),
        '%changed' => $this->serverDrupalUser
          ->deriveEmailFromLdapResponse($this->ldapEntry),
      ]);
    }
    elseif ($update_type === 'update_notify') {
      $this->messenger
        ->addStatus($this
        ->t('Your e-mail has been updated to match your current account (%mail).', [
        '%mail' => $this->serverDrupalUser
          ->deriveEmailFromLdapResponse($this->ldapEntry),
      ]));
    }
  }
}