vendor/knpuniversity/oauth2-client-bundle/src/Security/Helper/FinishRegistrationBehavior.php line 54

Open in your IDE?
  1. <?php
  2. /*
  3.  * OAuth2 Client Bundle
  4.  * Copyright (c) KnpUniversity <http://knpuniversity.com/>
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace KnpU\OAuth2ClientBundle\Security\Helper;
  10. use KnpU\OAuth2ClientBundle\Security\Exception\FinishRegistrationException;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. /**
  14.  * Use this trait if sometimes your authenticator requires people
  15.  * to "finish registration" before logging in.
  16.  */
  17. trait FinishRegistrationBehavior
  18. {
  19.     /**
  20.      * Call this from within your onAuthenticationFailure() method.
  21.      *
  22.      * @throws \LogicException
  23.      */
  24.     protected function saveUserInfoToSession(Request $requestFinishRegistrationException $e)
  25.     {
  26.         // save the user information!
  27.         if (!$request->hasSession() || !$request->getSession() instanceof SessionInterface) {
  28.             throw new \LogicException('In order to save user info, you must have a session available.');
  29.         }
  30.         $session $request->getSession();
  31.         $session->set(
  32.             'guard.finish_registration.user_information',
  33.             $e->getUserInformation()
  34.         );
  35.     }
  36.     /**
  37.      * Useful during registration to get your user information back out.
  38.      *
  39.      * @throws \LogicException
  40.      */
  41.     public function getUserInfoFromSession(Request $request)
  42.     {
  43.         if (!$request->hasSession() || !$request->getSession() instanceof SessionInterface) {
  44.             throw new \LogicException('In order to have saved user info, you must have a session available.');
  45.         }
  46.         $session $request->getSession();
  47.         return $session->get('guard.finish_registration.user_information');
  48.     }
  49. }