Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:09:37+00:00 2026-06-03T11:09:37+00:00

I am building a web application with Symfony 2, using the FOSUserBundle bundle. Users

  • 0

I am building a web application with Symfony 2, using the FOSUserBundle bundle.
Users create an account, login and start using the application.

What I want to achieve now is to have the user redirected to their account from any page they may be at if they are logged in.
This includes:

  • if they get back to the login page
  • if they get back to the registration page
  • if they go to the homepage of the website
  • once they confirm their email
  • once they reset their password

Basically the code would be something like this:

$container = $this->container;
$accountRouteName = "DanyukiWebappBundle_account";
if( $container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY') ){
    // authenticated (NON anonymous)
    $routeName = $container->get('request')->get('_route');
    if ($routeName != $accountRouteName) {
        return $this->redirect($this->generateUrl($accountRouteName));
    }
}

The problem is I don’t know where that code should go.
It should be executed for any request. In Symfony 1 I would have used a filter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:09:42+00:00Added an answer on June 3, 2026 at 11:09 am

    I found the solution myself:

    <?php
    
    namespace Danyuki\UserBundle\Listener;
    
    use Symfony\Component\HttpKernel\Event\GetResponseEvent;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    
    class LoggedInUserListener
    {
        private $router;
        private $container;
    
        public function __construct($router, $container)
        {
            $this->router = $router;
            $this->container = $container;
        }    
    
        public function onKernelRequest(GetResponseEvent $event)
        {
            $container = $this->container;
            $accountRouteName = "DanyukiWebappBundle_account";
            if( $container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY') ){
                // authenticated (NON anonymous)
                $routeName = $container->get('request')->get('_route');
                if ($routeName != $accountRouteName) {
                    $url = $this->router->generate($accountRouteName);
                    $event->setResponse(new RedirectResponse($url));
                }
            }
        }
    }
    

    And then, in the services.yml file of my bundle:

    services:
        kernel.listener.logged_in_user_listener:
                class: Danyuki\UserBundle\Listener\LoggedInUserListener
                tags:
                    - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
                arguments: [ @router, @service_container ]  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a web application using Symfony 1.4 and Doctrine for a school
I am building web application using Spring MVC Spring Security Hibenate MySQl I want
I'm building a web application that guides my users through the configuration and installation
I am building a web application that uses the database for Users, Security/roles, and
I am building a Web Application using asp.net (C#). I come from windows forms
I am building a web application that will need to allow users to save
I am building a web application using ASP.NET MVC that has two very distinct
I am building a web application and have been told that using object oriented
I'm building a web application with the Symfony Framework. The purpose of this app
We building big Web Application and we use mysql, we want to make mysql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.