You are here

public function NspiController::getCommunicationSettings in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 tests/modules/src/Controller/NspiController.php \Drupal\acquia_connector_test\Controller\NspiController::getCommunicationSettings()
  2. 3.x tests/modules/src/Controller/NspiController.php \Drupal\acquia_connector_test\Controller\NspiController::getCommunicationSettings()

Test return communication settings for an account.

Parameters

\GuzzleHttp\Psr7\Request $request: Request.

Return value

\GuzzleHttp\Psr7\Response JsonResponse.

File

tests/modules/src/Controller/NspiController.php, line 337

Class

NspiController
Class NspiController.

Namespace

Drupal\acquia_connector_test\Controller

Code

public function getCommunicationSettings(Request $request) {
  $data = json_decode($request
    ->getBody(), TRUE);
  $fields = [
    'time' => 'is_numeric',
    'nonce' => 'is_string',
    'hash' => 'is_string',
  ];

  // Authenticate.
  $result = $this
    ->basicAuthenticator($fields, $data);
  if (!empty($result['error'])) {
    return new Response(200, [], json_encode($result));
  }
  if (!isset($data['body']) || !isset($data['body']['email'])) {
    return new Response(self::ACQTEST_SUBSCRIPTION_SERVICE_UNAVAILABLE, [], json_encode($this
      ->errorResponse(self::ACQTEST_SUBSCRIPTION_VALIDATION_ERROR, $this
      ->t('Invalid arguments'))));
  }
  $account = user_load_by_mail($data['body']['email']);
  if (empty($account) || $account
    ->isAnonymous()) {
    return new Response(self::ACQTEST_SUBSCRIPTION_SERVICE_UNAVAILABLE, [], json_encode($this
      ->errorResponse(self::ACQTEST_SUBSCRIPTION_VALIDATION_ERROR, $this
      ->t('Account not found'))));
  }
  $result = [
    'algorithm' => 'sha512',
    'hash_setting' => substr($account
      ->getPassword(), 0, 12),
    'extra_md5' => FALSE,
  ];
  return new Response(200, [], json_encode($result));
}