PHPackages                             c975l/user-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. c975l/user-bundle

ActiveSymfony-bundle

c975l/user-bundle
=================

Bundle to manage user profile, by users and admin

v4.0.1(4y ago)36081MITPHPPHP \*CI failing

Since Feb 19Pushed 4y ago2 watchersCompare

[ Source](https://github.com/975L/UserBundle)[ Packagist](https://packagist.org/packages/c975l/user-bundle)[ Docs](https://github.com/975L/UserBundle)[ Fund](https://buymeacoff.ee/laurentmarquet)[ Fund](https://opencollective.com/laurent-marquet)[ RSS](/packages/c975l-user-bundle/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (17)Versions (106)Used By (0)

UserBundle
==========

[](#userbundle)

Directly inspired from [FOSUserBundle](https://github.com/FriendsOfSymfony/FOSUserBundle), and migration of [c975L/UserFilesBundle](https://github.com/975L/UserFilesBundle/tree/master), UserBundle does the following:

- Ensure **respect of GDPR rules** such as giving agreement to store data, exporting data,
- Stores users in database **(using doctrine)**,
- Provides multiples types of entities for User (see below),
- Allows extending those entities to add your own fields,
- Allows users to manage their profile and data,
- Validates data such as Siret, VAT number,
- Displays a "challenge" for sign up (no Captcha, etc.),
- Allows the possibility to disable sign up (for registering only one or more users and then no more),
- Provides forms for Sign in, Sign up, Modify profile, Change password and Reset password,
- Provides public profile (you can disabled it in config),
- Allows extending those forms,
- Sends email about sign up and password reset to the user via [c975LEmailBundle](https://github.com/975L/EmailBundle) as `c975LEmailBundle` provides the possibility to save emails in a database, there is an option to NOT do so via this Bundle,
- Integrates with [c975LToolbarBundle](https://github.com/975L/ToolbarBundle),
- Allows to connect with social networks via [HWIOAuthBundle](https://github.com/hwi/HWIOAuthBundle),
- Provides a sql script to migrate from FOSUserBundle,
- Allows to display Gravatar's image linked to the email address,
- Allows to display Social network's image linked to the account,
- Provides a divData to allows access user's data from javascript,
- Allows easy overridding of templates or parts of them to minimize the number of the overriden files to the essential,
- Allows to define a number of attempts for sign in and then add a delay before being able to sign in again,
- Resetting password form will NOT send email for inexisting accounts while displaying so, this un-allows checking for registered emails,
- Allows user to removes its allowing to use its data while maintaining its account, in this case the account will be marked as NOT enabled,
- Sends email when user changes (or resets) passsword to allow contact website if he/she has not initiated this action,
- integrates an **API** to authenticate/create/display/modify/delete users in json format,

[UserBundle dedicated web page](https://975l.com/en/pages/user-bundle).

[UserBundle API documentation](https://975l.com/apidoc/c975L/UserBundle.html).

Bundle installation
-------------------

[](#bundle-installation)

### Step 1: Download the Bundle

[](#step-1-download-the-bundle)

v3.x works with Symfony 4.x. **Use v2.x for Symfony 3.x**Use [Composer](https://getcomposer.org) to install the library

```
    composer require c975l/user-bundle
```

### Step 2: Configure the Bundle

[](#step-2-configure-the-bundle)

Check dependencies for their configuration:

- [Symfony Mailer](https://github.com/symfony/mailer)
- [Doctrine](https://github.com/doctrine/DoctrineBundle)
- [c975LEmailBundle](https://github.com/975L/EmailBundle)
- [Misd\\PhoneNumberBundle](https://github.com/misd-service-development/phone-number-bundle)
- [lcobucci\\JWT](https://github.com/lcobucci/jwt)

And finally in `/config/packages/security.yml`

```
security:
    encoders:
        #The entity you want to use
        c975L\UserBundle\Entity\User: auto
    role_hierarchy:
        ROLE_MODERATOR: 'ROLE_USER'
        ROLE_ADMIN: [ROLE_MODERATOR, ROLE_USER]
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_MODERATOR, ROLE_USER]
    providers:
        c975_l_userbundle:
            entity:
                #The entity you want to use
                class: c975L\UserBundle\Entity\User
    firewalls:
        main:
            pattern: ^/
            provider: c975_l_userbundle
            form_login:
                login_path: user_signin
                check_path: user_signin
                default_target_path: user_dashboard
                csrf_token_generator: security.csrf.token_manager
            remember_me:
                secret: '%secret%'
                lifetime: 31536000
                path: /
                secure: true
            anonymous: true
            logout:
                path: user_signout
                handlers: [c975L\UserBundle\Listener\LogoutListener]
```

### Step 3: Create MySql table

[](#step-3-create-mysql-table)

Use `/Resources/sql/user.sql` to create the tables `user` and `user_archives`. The `DROP TABLE` are commented to avoid dropping by mistake. It will also create a stored procedure `sp_UserArchive()`.

### Step 4: Enable the Routes

[](#step-4-enable-the-routes)

Then, enable the routes by adding them to the `/config/routes.yaml` file of your project:

```
c975_l_user:
    resource: "@c975LUserBundle/Controller/"
    type: annotation
    prefix: /
    #Multilingual website use the following
    #prefix: /{_locale}
    #defaults:   { _locale: '%locale%' }
    #requirements:
    #    _locale: en|fr|es
```

### Step 5: install assets to web folder

[](#step-5-install-assets-to-web-folder)

Install assets by running

```
php bin/console assets:install --symlink
```

It will create a link from folder `Resources/public/` in your web folder.

### Overriding Templates

[](#overriding-templates)

It is strongly recommended to use the [Override Templates from Third-Party Bundles feature](https://symfony.com/doc/current/templating/overriding.html) to integrate fully with your site.

For this, simply, create the following structure `/templates/bundles/c975LUserBundle/` in your app and then duplicate the file `layout.html.twig` in it, to override the existing Bundle files, then apply your needed changes.

You can also override:

- `/templates/bundles/c975LUserBundle/fragments/deleteAccountInfo.html.twig` that will list the implications, by deleting account, for user, displayed in the delete account page.
- `/templates/bundles/c975LUserBundle/fragments/dashboardActions.html.twig` to add your own actions (or whatever) in the dashboard i.e.
- `/templates/bundles/c975LUserBundle/fragments/avatar.html.twig` to modify the display of avatar (26/03/2018)

You can add a navbar menu via `{% include('@c975LUser/fragments/navbarMenu.html.twig') %}`. You can override it, if needed, or simply override `/templates/bundles/c975LUserBundle/fragments/navbarMenuActions.html.twig` to add actions above it.

### Routes

[](#routes)

The Routes availables are:

- user\_signup
- user\_signup\_confirm
- user\_signin
- user\_config
- user\_dashboard
- user\_display
- user\_export
- user\_modify
- user\_change\_password
- user\_reset\_password
- user\_reset\_password\_confirm
- user\_signout
- user\_delete
- user\_public\_profile

### Entities

[](#entities)

You must choose an entity linked to your needs and specify it in the `/config/packages/security.yml`. Available entities are the following:

- `c975L/UserBundle/Entity/UserLight`: light user with minimum requirements
- `c975L/UserBundle/Entity/User`: default user
- `c975L/UserBundle/Entity/UserAddress`: default user + address fields
- `c975L/UserBundle/Entity/UserBusiness`: default user + business/association fields
- `c975L/UserBundle/Entity/UserSocial`: default user + social network fields
- `c975L/UserBundle/Entity/UserFull`: default user + address + business + social + multilingual fields

To help you choose, the fields are the following:

LIGHT

- id
- allow\_use
- identifier
- email
- creation
- enabled
- salt
- password
- token
- password\_request
- roles

DEFAULT

- gender
- firstname
- lastname
- avatar
- latest\_signin
- latest\_signout
- locale

ADDRESS

- address
- address2
- postal
- town
- country
- phone
- fax

BUSINESS

- business\_type
- business\_name
- business\_address
- business\_address2
- business\_postal
- business\_town
- business\_country
- business\_siret
- business\_vat
- business\_phone
- business\_fax

SOCIAL

- social\_network
- social\_id
- social\_token
- social\_picture

You can also create your own Class by extending one of the Abstract classes with the following code:

```
