I am new to Symfony 2 and never used any framework before.
I created 2 bundles, one for core site which url is as root / it is DefaultBundle then I created a new UserBundle and set all the routing to /user/ the login page is /user/login and it is working fine.
So far I am able to login the user and every thing seems working.
Question really is, how can I check in DefaultBundle that a user is logged in, so I show them Welcome User instead of login/register links on top right side of the front end website.
p.s. I dont need FOSuserBundle as answer,
below is from my security.yml file
jms_security_extra:
secure_all_services: false
expressions: true
security:
encoders:
Aala\Vital\UserBundle\Entity\User:
algorithm: plaintext
# encode_as_base64: false
# iterations: 1
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_MOD: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_MOD, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
user_area:
entity: {class: AalaVitalUserBundle:User, property: email}
firewalls:
login:
pattern: ^/user/login$
security: false
anonymous: true
user_area:
pattern: ^/user
form_login:
login_path: /user/login
check_path: /user/login_check
post_only: true
default_target_path: /user/
logout:
path: /user/logout
target: /user/
main:
pattern: ^/
security: true
anonymous: ~
access_control:
- { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user, roles: ROLE_USER }
My Folder Structure is as follows
-src
-Aala
-Vital
-FronendBundle
-UserBundle
Edit:
Is this can be done with dependency injection? if yes how to do that…
Solved
To share the authentication between two firewalls use
context. Below is the updated firewalls section from my security.yml file