Symfony 2 Login on main domain only

半腔热情 提交于 2019-12-08 06:17:06

问题


I am working on a application using multiple subdomains :

  • .domain.com
  • admin.domain.com
  • {username}.domain.com

    and so on.

I am using the FOSUserBundle to handle my users and I am wondering how I could force users to login only on the main .domain.com.

For example, when a user is trying to access the administration, redirect him to http://domain.com/login instead of http://admin.domain.com/login.

I was thinking about a LoginListener somewhere, but I have no idea where I could create it and how to override the login process.

Any ideas ?? Thank you !


回答1:


Add a host directive to your login route.

# app/config/routing.yml
login_route:
    path:     /login
    host:     "domain.com"

Then use this route in your firewall configuration as the login_path:

# app/config/security.yml
security:
    # ...
    firewalls:
        your_firewall_name:
            # ...
            form_login:
                 login_path: login_route
                 # ...

Now everytime the url for login_route is generated it automatically refers to the host domain.com.



来源:https://stackoverflow.com/questions/20257027/symfony-2-login-on-main-domain-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!