You are here

public function UserAuthenticator::authenticateExistingUser in Social Auth 8.2

Same name and namespace in other branches
  1. 3.x src/User/UserAuthenticator.php \Drupal\social_auth\User\UserAuthenticator::authenticateExistingUser()

Authenticates and redirects existing users in authentication process.

Parameters

\Drupal\user\UserInterface $drupal_user: User object to authenticate.

2 calls to UserAuthenticator::authenticateExistingUser()
UserAuthenticator::authenticateWithEmail in src/User/UserAuthenticator.php
Authenticates user by email address.
UserAuthenticator::authenticateWithProvider in src/User/UserAuthenticator.php
Authenticates user using provider.

File

src/User/UserAuthenticator.php, line 263

Class

UserAuthenticator
Manages Drupal authentication tasks for Social Auth.

Namespace

Drupal\social_auth\User

Code

public function authenticateExistingUser(UserInterface $drupal_user) {

  // If Admin (user 1) can not authenticate.
  if ($this
    ->isAdminDisabled($drupal_user)) {
    $this
      ->nullifySessionKeys();
    $this->messenger
      ->addError($this
      ->t('Authentication for Admin (user 1) is disabled.'));
    $this->response = $this
      ->getLoginFormRedirection();
    return;
  }

  // If user can not login because of their role.
  $disabled_role = $this
    ->isUserRoleDisabled($drupal_user);
  if ($disabled_role) {
    $this->messenger
      ->addError($this
      ->t("Authentication for '@role' role is disabled.", [
      '@role' => $disabled_role,
    ]));
    $this->response = $this
      ->getLoginFormRedirection();
    return;
  }

  // If user could be logged in.
  if ($this
    ->loginUser($drupal_user)) {
    $this->response = $this
      ->getPostLoginRedirection();
  }
  else {
    $this
      ->nullifySessionKeys();
    $this->messenger
      ->addError($this
      ->t('Your account has not been approved yet or might have been canceled, please contact the administrator.'));
    $this->response = $this
      ->getLoginFormRedirection();
  }
}