eZ trouble shooting: Login into the new stack from the legacy stack
eZ Systems changed the way how logins are handled a few versions ago (versions > 5.3).
If your application still uses the legacy stack and you are using your own login module in the old stack you might have a problem: the new eZ (and Symfony) version will not login the user on the Symfony stack.
If you want to login a user in the new stack as well as in the legacy stack this solution in eZ 4 might help:
$userId = = 1224;
$container = ezpKernel::instance()->getServiceContainer();
try {
$repository = $container->get('ezpublish.api.repository');
$userService = $repository->getUserService();
$ezUser = $userService->loadUser($userId);
if ($ezUser) {
$user = new CoreUser($ezUser);
$providerKey = 'ezpublish_front';
$token = new UsernamePasswordToken($user, null, $providerKey);
$securityContextService = $container->get('security.context');
$securityContextService->setToken($token);
$repository->setCurrentUser($ezUser);
} else {
eZDebug::writeError('User with id '.$userId.' in new stack not found, login falied',__METHOD__);
}
} catch (\Exception $e) {
eZDebug::writeError("Exception while trying to login on new stack: ". $e->getMessage());
}