src/moocApp/MoocBundle/Redirection/AfterLoginRedirection.php
/**
 * @param Request $request  
 * @param TokenInterface $token    
 * @return RedirectResponse    
 */
@param Request $request
@param TokenInterface $token
@return RedirectResponse
@param Request $request @param TokenInterface $token @return RedirectResponse
public function onAuthenticationSuccess(Request $request, TokenInterface $token) {
$roles = $token->getRoles();
$rolesTab = array_map(function($role) {
return $role->getRole();
}, $roles);
        $user=$token->getUser();
        if (in_array('ROLE_SUPER_ADMIN', $rolesTab, true)) {
            $redirection = new RedirectResponse($this->router->generate('dashboard'));
        }
        elseif (in_array('ROLE_APPRENANT', $rolesTab, true)) {
            $redirection = new RedirectResponse($this->router->generate('fos_user_profile_show'));
        }
        elseif (in_array('ROLE_ORGANISME', $rolesTab, true)) {
            return $redirection = new RedirectResponse($this->router->generate('fos_user_profile_show'));
        }
        else {
            $redirection = new RedirectResponse($this->router->generate('dashboard'));
        }
        return $redirection;
    }
public function onAuthenticationSuccess ( Request $ request , TokenInterface $ token ) { $ roles = $ token -> getRoles ( ) ; $ rolesTab = array_map ( function ( $ role ) { return $ role -> getRole ( ) ; } , $ roles ) ; $ user = $ token -> getUser ( ) ; if ( in_array ( 'ROLE_SUPER_ADMIN' , $ rolesTab , true ) ) { $ redirection = new RedirectResponse ( $ this -> router -> generate ( 'dashboard' ) ) ; } elseif ( in_array ( 'ROLE_APPRENANT' , $ rolesTab , true ) ) { $ redirection = new RedirectResponse ( $ this -> router -> generate ( 'fos_user_profile_show' ) ) ; } elseif ( in_array ( 'ROLE_ORGANISME' , $ rolesTab , true ) ) { return $ redirection = new RedirectResponse ( $ this -> router -> generate ( 'fos_user_profile_show' ) ) ; } else { $ redirection = new RedirectResponse ( $ this -> router -> generate ( 'dashboard' ) ) ; } return $ redirection ; }
@param Request $request
 @param TokenInterface $token
 @return RedirectResponse
@param Request $request @param TokenInterface $token @return RedirectResponse
// Get list of roles for current user       // Tranform this list in array        // S'il s'agit d'un admin ou d'un super admin on le redirige vers le backoffice