You are here

public function LinkedInAuthController::userRegisterCallback in Open Social 8.6

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

Registers the new account after redirect from LinkedIn.

Return value

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

1 string reference to 'LinkedInAuthController::userRegisterCallback'
social_auth_linkedin.routing.yml in modules/custom/social_auth_linkedin/social_auth_linkedin.routing.yml
modules/custom/social_auth_linkedin/social_auth_linkedin.routing.yml

File

modules/custom/social_auth_linkedin/src/Controller/LinkedInAuthController.php, line 139

Class

LinkedInAuthController
Class LinkedInAuthController.

Namespace

Drupal\social_auth_linkedin\Controller

Code

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

  // Check whether user account exists. If account already exists,
  // authorize the user and redirect him to the account page.
  $account = $this
    ->entityTypeManager()
    ->getStorage('user')
    ->loadByProperties([
    'linkedin_id' => $profile['id'],
  ]);
  if ($account) {
    $account = current($account);
    if (!$account
      ->get('status')->value) {
      drupal_set_message($this
        ->t('You already have account on this site, but your account is blocked. Contact the site administrator.'), 'error');
      return $this
        ->redirect('user.register');
    }
    user_login_finalize($account);
    return $this
      ->redirect('entity.user.canonical', [
      'user' => $account
        ->id(),
    ]);
  }

  // Save email and name to session to use for auto fill the registration
  // form.
  $data_handler = $this->networkManager
    ->createInstance('social_auth_linkedin')
    ->getDataHandler();
  $data_handler
    ->set('access_token', $this->accessToken);
  $data_handler
    ->set('mail', $profile['emailAddress']);
  $data_handler
    ->set('name', $profile['formattedName']);
  drupal_set_message($this
    ->t('You are now connected with @network, please continue registration', [
    '@network' => $this
      ->t('LinkedIn'),
  ]));
  return $this
    ->redirect('user.register', [
    'provider' => 'linkedin',
  ]);
}