Last active
May 1, 2017 12:00
-
-
Save teeyo/121e21b35d71a9ab4a8f321043b6f6cd to your computer and use it in GitHub Desktop.
Redirecting authenticated users when they try to access login page. [FOSUserBundle - Symfony 3]
This file contains 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 | |
/* | |
* This file is part of the FOSUserBundle package. | |
* | |
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace TeeyoUserBundle\Controller; | |
use FOS\UserBundle\Controller\SecurityController as BaseController; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\Security\Core\Exception\AuthenticationException; | |
use Symfony\Component\Security\Core\Security; | |
class SecurityController extends BaseController | |
{ | |
/** | |
* Renders the login template with the given parameters. Overwrite this function in | |
* an extended controller to provide additional data for the login template. | |
* | |
* @param array $data | |
* | |
* @return Response | |
*/ | |
protected function renderLogin(array $data) | |
{ | |
/** | |
* If the user has already logged in (marked as is authenticated fully by symfony's security) | |
* then redirect this user back (in my case, to the dashboard, which is the main entry for | |
* my logged in users) | |
*/ | |
if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { | |
return $this->redirectToRoute('teeyo_quiz_homepage'); | |
} | |
return $this->render('@FOSUser/Security/login.html.twig', $data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment