You are here

public function GoogleAuthController::userLoginCallback in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::userLoginCallback()
  2. 8.2 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::userLoginCallback()
  3. 8.3 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::userLoginCallback()
  4. 8.4 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::userLoginCallback()
  5. 8.5 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::userLoginCallback()
  6. 8.6 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::userLoginCallback()
  7. 8.7 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::userLoginCallback()
  8. 8.8 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::userLoginCallback()

Authorizes the user after redirect from Google.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Returns a RedirectResponse.

1 string reference to 'GoogleAuthController::userLoginCallback'
social_auth_google.routing.yml in modules/custom/social_auth_google/social_auth_google.routing.yml
modules/custom/social_auth_google/social_auth_google.routing.yml

File

modules/custom/social_auth_google/src/Controller/GoogleAuthController.php, line 83

Class

GoogleAuthController
Class GoogleAuthController.

Namespace

Drupal\social_auth_google\Controller

Code

public function userLoginCallback() {
  $sdk = $this
    ->getSdk('login');
  if ($sdk instanceof RedirectResponse) {
    return $sdk;
  }
  $this->authManager
    ->setSdk($sdk);
  $profile = $this
    ->getProfile('login');
  if ($profile instanceof RedirectResponse) {
    return $profile;
  }

  // Check whether user account exists.
  $account = $this
    ->entityTypeManager()
    ->getStorage('user')
    ->loadByProperties([
    'google_id' => $profile
      ->getId(),
  ]);
  if (!$account) {
    return $this
      ->redirect('social_auth_google.user_login_notice');
  }
  $account = current($account);
  if (!$account
    ->get('status')->value) {
    drupal_set_message($this
      ->t('Your account is blocked. Contact the site administrator.'), 'error');
    return $this
      ->redirect('user.login');
  }

  // Authorize the user and redirect him to the account page.
  user_login_finalize($account);
  return $this
    ->redirect('entity.user.canonical', [
    'user' => $account
      ->id(),
  ]);
}