This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Setup & design » How to override the login form in eZ5 ?

How to override the login form in eZ5 ?

How to override the login form in eZ5 ?

Monday 18 March 2013 5:02:23 pm - 1 reply

Hi everyone !

I'm trying to use eZPublish 5 and I would like to override the login form and use a twig template and a symfony controller action instead if possible.

I was thinking of doing a simple form with a username and password in a new twig template and then create an action with the following code :


public function loginAction(Request $request)


$user = $request->request->get('username');

$password = $request->request->get('password');

$repository = $this->get('ezpublish.api.repository');

$userService = $repository->getUserService();

$user = $userService->loadUserByCredentials( $user, $password );$repository->setCurrentUser( $user );

return $this->render("MyBundle:index.html.twig"blunk.gif Emoticon


But when I submit this login form, I'm not logged in, I'm still anonymous. What do I do wrong ? Thanks a lot!

Thursday 02 May 2013 3:51:29 pm

I guess, the problem is, you just loaded a eZ user object. This is necessary if you want to create, read etc. content with a specific user from the eZ 5 public API.
Loading a user object via loadUserByCredentials() does not create a security context within your Symfony application and therefore you are not logged.


I had a similar issue few days ago and only could workaround it, using the default way of logging in which is legacy module loading of /user/login at the moment (see src/EzSystems/DemoBundle/Resources/views/page_header_links.html.twig). This is a really bad practice and I really don't understand, why eZ would do this.

Maybe I missed something, but as far as I understood the sources, I'm only able to determine, if I'm logged in already e.g. via:

$securityContext = $this->container->get('security.context');
$currentlyLoggedInEzUser = $securityContext->getToken()->getUser()->getAPIUser(); 

If anybody has an idea of doing this the Symfony way, a notice in confluence or here is appreciated. Thanks! Hope this helps..


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from