Created
November 23, 2016 11:44
-
-
Save akovalyov/e7598581de38b9fdbfa0407709fd6800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Security\Authentication; | |
use AGILEmentBundle\Entity\User; | |
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | |
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | |
class AutoLogin | |
{ | |
const FIREWALL_APP = 'main'; | |
private $tokenStorage; | |
public function __construct(TokenStorageInterface $tokenStorage) | |
{ | |
$this->tokenStorage = $tokenStorage; | |
} | |
public function login(User $user, $firewall = self::FIREWALL_APP) | |
{ | |
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); | |
$this->tokenStorage->setToken($token); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment