Question

i'm having this project which allows a user to login on multiple tablets.

on my interface i have list of users who are "online" ( last seen < 2 minutes ) .

i would like , by selecting one of these, be redirected to a login page where the username is already filled or set, and just have to specify the user's password.

This feature would allows user to simply switch between the differents tablets.

for the moment i made my online user list works and redirect to the fos user bundle overrided login form.

i think i should override a second time the login form and may be the controller, but i actually wondering if there is already a built-in feature.

Was it helpful?

Solution

Okay here is my answer ( which works of course )

1) you need to override fosUserBundle SecurityController and routing to add your custom code :

  Copy from FOS\UserBundle\Controller\SecurityController
  To your bundle ( for example : Acme\UserBundle\Controller

  Copy from FOS\UserBundle\Ressources\config\routing\security.xml
  To your bundle ( for example : Acme\UserBundle\Ressources\config\routing\security.xml

2) in your app\config\routing.yml

  Change : 
        fos_user_security:
            resource: "@FOSUserBundle/Resources/config/routing/security.xml"
  To :
        fos_user_security:
            resource: "@ACMEUserBundle/Resources/config/routing/security.xml"

( ACME here is you app name )

3) in your Acme\UserBundle\Controller\SecurityController.php

  Add the following ( after line 43 ):
    /**
     * Custom login if we want to prefill login with an online user email
     */
    if ( $lastUsername === null && $request->get('email') != '' ) 
        $lastUsername            = $request->get('email');

Now we are able to use login in both standard mode and custom mode which allow to switch between online users from different devices without loosing security .

i m conscious that having an email in get parameter isn't very clean code, but this project is running through an webview in a mobile app and the url is never displayed .

the code should be updated in case of post method .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top