philiplb/crudlexuser

CRUDlexUser is a library offering an user provider for symfony/security.

0.14.0 2018-09-07 14:01 UTC

This package is not auto-updated.

Last update: 2024-11-16 10:33:55 UTC


README

CRUDlexUser is a library offering an user provider for symfony/security.

Total Downloads Latest Stable Version Latest Unstable Version License

API Documentation

The CRUDlexUser API itself is documented here:

Upcoming bleeding edge:

Generated via (assuming APIGen is globally installed like composer global require ... and the PHP version is at maximum 7.1):

~/.composer/vendor/bin/apigen generate

Package

CRUDlexUser uses SemVer for versioning. Currently, the API changes quickly due to be < 1.0.0, so take care about notes in the changelog when upgrading.

Stable

"require": {
    "philiplb/crudlexuser": "0.14.0"
}

Bleeding Edge

"require": {
    "philiplb/crudlexuser": "0.15.x-dev"
}

Usage

This library offers two parts. First, a management interface for your admin panel to perform CRUD operations on your userbase and second, an symfony/security UserProvider offering in order to connect the users with the application.

The Admin Panel

The admin panel for your users is based on CRUDlex. So all you have to do is to add the needed entities to your crud.yml from the following sub chapters.

In order to get the salt generated and the password hashed, you have to let the library add some CRUDlex events in your initialization:

$crudUserSetup = new CRUDlex\UserSetup();
$crudUserSetup->addEvents($app['crud']->getData('user'));

Users

user:
    label: User
    table: user
    fields:
        username:
            type: text
            label: Username
            required: true
            unique: true
        password:
            type: text
            label: Password Hash
            description: 'Set this to your desired password. Will be automatically converted to an hash value not meant to be readable.'
            required: true
        salt:
            type: text
            label: Password Salt
            description: 'Auto populated field on user creation. Used internally.'
            required: false
        userRoles:
            type: many
            label: Roles
            many:
                entity: role
                nameField: role
                thisField: user
                thatField: role

Plus any more fields you need. Recommended for the password reset features:

email:
    type: text
    label: E-Mail
    required: true
    unique: true

Roles

role:
    label: Roles
    table: role
    fields:
        role:
            type: text
            label: Role
            required: true

Password Reset

In case you want to use the password reset features:

passwordReset:
    label: Password Resets
    table: password_reset
    fields:
        user:
            type: reference
            label: User
            reference:
                nameField: username
                entity: user
            required: true
        token:
            type: text
            label: Token
            required: true
        reset:
            type: datetime
            label: Reset

The UserProvider

Simply instantiate and add it to your symfony/security configuration:

$userProvider = new CRUDlex\UserProvider($app['crud']->getData('user'), $app['crud']->getData('userRole'));
$app->register(new Silex\Provider\SecurityServiceProvider(), array(
    'security.firewalls' => array(
        'admin' => array(
            //...
            'users' => $userProvider
        ),
    ),
));

Accessing Data of the Logged in User

In order to get the user data from the logged in user in your controller, you might grab him like this:

$user = $app['security.token_storage']->getToken()

You get back a CRUDlex\User instance having some getters, see the API docs.

Build Status

Build Status Coverage Status

Code Quality

SensioLabsInsight Scrutinizer Code Quality