简体   繁体   English

Symfony会话,不同的路线,不同的会话

[英]Symfony session, different route, different session

So, i have two differents route on my project : 因此,我在项目中有两种不同的路线:

/memberarea
/mobile

The first is for the web version on my application, and the second is for the mobile version. 第一个用于我的应用程序上的Web版本,第二个用于移动版本。

Here you can see a part of my security.yml : 在这里,您可以看到我的security.yml的一部分:

firewalls:
    main:
        pattern: ^/
        form_login:
            login_path: /
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            default_target_path: /memberarea
        logout:       true
        anonymous:    true
    mobile:
        pattern: /mobile/.*
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/memberarea, roles: IS_AUTHENTICATED_FULLY }
    - { path: ^/mobile, roles: IS_AUTHENTICATED_FULLY }

My problem, when a user login on mobile, i create a session on symfony with the firewall mobile like : $token = new UsernamePasswordToken($user, $request->get('password'), "mobile", $user->getRoles());..... 我的问题是,当用户在移动设备上登录时,我使用防火墙mobile在symfony上创建了一个会话,例如: $token = new UsernamePasswordToken($user, $request->get('password'), "mobile", $user->getRoles());.....

this user can use all route in /mobile , it's ok. 该用户可以使用/mobile所有路由,没关系。 But he can use /memberarea too. 但是他也可以使用/memberarea How can i do for login a user just for /mobile , just for /memberarea or for both ? 我该如何仅针对/mobile ,仅针对/memberarea或同时为两者登录用户?

If I have correctly understood, you want to log into your mobile application with a different session than on your web application. 如果我已正确理解,您希望使用与Web应用程序不同的会话登录到移动应用程序。

What I am doing in order to obtain this result is setting up in my security.yml file a different context for each firewall I have. 为了获得此结果,我正在做的是在security.yml文件中为我拥有的每个防火墙设置不同的上下文。

(If you want to have one session for both you must have the context with the same value for the given firewalls.) (如果您要同时进行两个会话,那么对于给定的防火墙,必须使上下文具有相同的值。)

File: app/config/security.yml 文件:app / config / security.yml

firewalls:
  main:
      pattern: ^/
      **context: user**
      form_login:
          login_path: /
          provider: fos_userbundle
          csrf_provider: form.csrf_provider
          default_target_path: /memberarea
      logout:       true
      anonymous:    true
  mobile:
      pattern: /mobile/.*
      *context: mobile_user*
      logout:       true
      anonymous:    true

Hope this helped. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM