Last active
September 8, 2016 16:23
-
-
Save mauricios/ad06d3cf1b5328aee046759f9807d52e to your computer and use it in GitHub Desktop.
eZ Platform Service to login user programatically
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 Vendor\MyLoginBundle\Services; | |
use Symfony\Component\HttpFoundation\RequestStack, | |
Symfony\Component\HttpFoundation\Response, | |
Symfony\Component\HttpFoundation\Cookie; | |
class LoginService | |
{ | |
private $requestStack; | |
public function __construct(RequestStack $requestStack) | |
{ | |
$this->requestStack = $requestStack; | |
} | |
public function setLoggedInUser($userId) | |
{ | |
$session = $this->requestStack->getCurrentRequest()->getSession(); | |
$session->set('eZUserLoggedInID', $userId); | |
$response = new Response(); | |
$response->headers->setCookie(new Cookie('is_logged_in', 'true')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should inject the requestStack in the service configuration: