kayue / KayueWordpressBundle

A Symfony 2 bundle for providing WordPress repositories and authenticating users (login).
101 stars 43 forks source link

How to use this an FOSUserBundle for login #49

Closed mattsnowboard closed 10 years ago

mattsnowboard commented 10 years ago

How do I use both this and FOSUserBundle for login?

I want to allow admins on my WP site to login to Symfony, but I'm using FOSUserBundle for normal users.

Do I need separate login forms or can I have one form that tries FOSUserBundle and falls back to Wordpress with KayueWordpressBundle?

So far I have this (but only FOSUserBundle works):

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512
        Kayue\WordpressBundle\Entity\User:
            id: kayue_wordpress.security.encoder.phpass

    role_hierarchy:
        ROLE_LIMITED_ADMIN: ROLE_USER
        ROLE_ADMIN_RO:    [ROLE_LIMITED_ADMIN]
        ROLE_ADMIN:       [ROLE_ADMIN_RO]
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    access_decision_manager:
        strategy: unanimous

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email
        wordpress:
            entity:
                class: Kayue\WordpressBundle\Entity\User
                property: username
                manager_name: wordpress

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true
            switch_user:  true
            kayue_wordpress: ~
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN_RO }
        - { path: ^/dash/, role: ROLE_USER }
        - { path: ^/apply/, role: ROLE_USER }
        - { path: ^/profile, role: ROLE_NEW_USER }
mattsnowboard commented 10 years ago

And I figured it out...needed a chain_provider

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512
        Kayue\WordpressBundle\Entity\User:
            id: kayue_wordpress.security.encoder.phpass

    role_hierarchy:
        ROLE_LIMITED_ADMIN: ROLE_USER
        ROLE_ADMIN_RO:    [ROLE_LIMITED_ADMIN]
        ROLE_ADMIN:       [ROLE_ADMIN_RO]
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    access_decision_manager:
        strategy: unanimous

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email
        wordpress:
            entity:
                class: Kayue\WordpressBundle\Entity\User
                property: username
                manager_name: wordpress
        fos_wp_chain:
            chain:
                providers: [ fos_userbundle, wordpress ]

    firewalls:
        main:
            pattern: ^/
            provider: fos_wp_chain
            form_login:
                provider: fos_wp_chain
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true
            switch_user:  true
            kayue_wordpress: ~
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN_RO }
        - { path: ^/dash/, role: ROLE_USER }
        - { path: ^/apply/, role: ROLE_USER }
        - { path: ^/profile, role: ROLE_NEW_USER }
kayue commented 10 years ago

Great :+1: