Installation

Install via composer

Note

This bundle uses symfony flex recipes to install further files via composer. Please check that flex is already configured in your project as it is part of the installation.

$ composer require enhavo/user-bundle ^0.8

Dependencies

This bundle has some other enhavo dependencies. Please check the installation guide for the other dependencies first, before you go on. Note that the Install via composer section for the other bundles are executed automatically within this bundle and you don’t need to repeat that step. Just skip and go on with further steps.

Note

Read the output after Install via composer carefully. All dependencies, which need further steps by you mentioned there.

Add node package

Execute following command to add required node package:

$ yarn add @enhavo/user

Register encore package

Add following entrypoint to the enhavo section in webpack.config.js file.

// import
const UserPackage = require('@enhavo/user/Encore/EncoreRegistryPackage');

// register package
.register(new UserPackage());

Change configuration

Update your config/packages/security.yaml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

        admin:
            pattern:  ^/admin/.*
            context: user
            form_login:
                provider:       fos_userbundle
                login_path:     /admin/login
                use_forward:    false
                check_path:     /admin/login/check
                failure_path:   /admin/login
                default_target_path: /admin
            logout:
                path:   /admin/logout
                target: /admin/login
            anonymous:  true

        user:
            pattern: ^/user/.*
            context: user
            form_login:
                provider:       fos_userbundle
                login_path:     /user/login
                use_forward:    false
                check_path:     /user/login/check
                failure_path:   /user/login
                default_target_path: /user/profile
            logout:
                path:   /user/logout
                target: /user/login
            anonymous:  true

        main:
            pattern: .*
            context: user
            form_login:
                provider:       fos_userbundle
                login_path:     /user/login
                use_forward:    false
                check_path:     /user/login/check
                failure_path:   /user/login
                default_target_path: /user/profile
            logout:
                path:   /user/logout
                target: /
            anonymous:  true

    access_control:
        - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/login/check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/reset-password, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

        - { path: ^/user/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/user/login/check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/user/registration, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/user/reset-password, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/user/, role: ROLE_USER }

Update your config/packages/enhavo.yaml

enhavo_app:
    menu:
        user:
            type: user

Migrate database

Execute following commands to upgrade your database.

$ bin/console doctrine:migrations:diff
$ bin/console doctrine:migrations:migrate

Build assets

Execute following commands to build your asset files.

$ yarn encore dev
% yarn routes:dump