You are here

public function SocialAuthUserManager::authenticateExistingUser in Social Auth 8

Authenticates and redirects existing users in authentication process.

Parameters

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

Return value

\Symfony\Component\HttpFoundation\RedirectResponse A redirect response.

1 call to SocialAuthUserManager::authenticateExistingUser()
SocialAuthUserManager::authenticateUser in src/SocialAuthUserManager.php
Creates and/or authenticates an user.

File

src/SocialAuthUserManager.php, line 187

Class

SocialAuthUserManager
Contains all logic that is related to Drupal user management.

Namespace

Drupal\social_auth

Code

public function authenticateExistingUser(UserInterface $drupal_user) {

  // If Admin (user 1) can not authenticate.
  if ($this
    ->isAdminDisabled($drupal_user)) {
    $this
      ->nullifySessionKeys();
    drupal_set_message($this
      ->t('Authentication for Admin (user 1) is disabled.'), 'error');
    return $this
      ->redirect('user.login');
  }

  // If user can not login because of their role.
  $disabled_role = $this
    ->isUserRoleDisabled($drupal_user);
  if ($disabled_role) {
    drupal_set_message($this
      ->t("Authentication for '@role' role is disabled.", array(
      '@role' => $disabled_role,
    )), 'error');
    return $this
      ->redirect('user.login');
  }

  // If user could be logged in.
  if ($this
    ->loginUser($drupal_user)) {
    return $this
      ->getLoginPostPath();
  }
  else {
    $this
      ->nullifySessionKeys();
    drupal_set_message($this
      ->t("Your account has not been approved yet or might have been canceled, please contact the administrator"), 'error');
    return $this
      ->redirect('user.login');
  }
}