public function AuthenticationByUser::getLoginData in CMS Content Sync 2.1.x
Same name and namespace in other branches
- 8 src/Controller/AuthenticationByUser.php \Drupal\cms_content_sync\Controller\AuthenticationByUser::getLoginData()
- 2.0.x src/Controller/AuthenticationByUser.php \Drupal\cms_content_sync\Controller\AuthenticationByUser::getLoginData()
@returns array
Throws
\Exception
File
- src/Controller/ AuthenticationByUser.php, line 82 
Class
- AuthenticationByUser
- Class AuthenticationByUser.
Namespace
Drupal\cms_content_sync\ControllerCode
public function getLoginData() {
  static $loginData = null;
  if (!empty($loginData)) {
    return $loginData;
  }
  $user = User::load(CMS_CONTENT_SYNC_USER_ID);
  // During the installation from an existing config for some reason CMS_CONTENT_SYNC_USER_ID is not set right after
  // the installation of the module, so we hae to double check that.
  if (is_null(CMS_CONTENT_SYNC_USER_ID)) {
    $user = User::load($this->keyValueDatabase
      ->get('cms_content_sync_user')
      ->get('uid'));
  }
  if (!$user) {
    throw new \Exception("Content Sync User not found. Encrypted data can't be read or saved.");
  }
  $loginData = $this->userData
    ->get('cms_content_sync', $user
    ->id(), 'sync_data');
  if (!$loginData) {
    throw new \Exception('No credentials for sync user found.');
  }
  $encryption_profile = EncryptionProfile::load(CMS_CONTENT_SYNC_ENCRYPTION_PROFILE_NAME);
  foreach ($loginData as $key => $value) {
    $loginData[$key] = \Drupal::service('encryption')
      ->decrypt($value, $encryption_profile);
  }
  return $loginData;
}