You are here

public function MainController::eatGingerbreadCookie in Bakery Single Sign-On System 8.2

Respond with account information.

File

src/Controller/MainController.php, line 66
Router call back functions for bakery SSO functions.

Class

MainController
Route callback functionlities.

Namespace

Drupal\bakery\Controller

Code

public function eatGingerbreadCookie(Request $request) {

  // storage populated in validate.
  $ginger_bread = Gingerbread::fromData($request->attributes
    ->get('bakery'));
  $request->attributes
    ->remove('bakery');
  $account = user_load_by_name($ginger_bread
    ->getAccountName());
  if (!$account && $ginger_bread
    ->getOrEmail()) {
    $account = user_load_by_mail($ginger_bread
      ->getAccountName());
  }

  /** @var \Drupal\user\UserInterface|false $account */
  if ($account) {
    $this
      ->saveChildUid($account, $ginger_bread
      ->getChild(), $ginger_bread
      ->getChildUid());
    $fields = [];

    // Add any synced fields.
    $config = $this
      ->config('bakery.settings');
    foreach ($config
      ->get('bakery_supported_fields') as $type => $enabled) {
      if ($enabled && $account->{$type}) {
        $fields[$type] = $account->{$type};
      }
    }
    $message = $this->kitchen
      ->bakeData(new GingerbreadReturn($account
      ->getAccountName(), $account
      ->getEmail(), $account
      ->id(), $fields));
    return new Response($message);
  }
  return new Response('No account found', Response::HTTP_CONFLICT);
}