2017 © Pedro Peláez
 

symfony-bundle user-bundle

Managment User bundle

image

amillot/user-bundle

Managment User bundle

  • Monday, April 30, 2018
  • by amillot
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Create your User class

To use this bundle, you have to create your own User class which extends to AbstractUser class., (*1)

// src\Entity\User.php

<?php

declare(strict_types=1);

namespace App\Entity;

use amillot\UserBundle\Entity\AbstractUser;

class User extends AbstractUser
{
}

Encoding Passwords

You can control how your user password is encoded in security.yaml., (*2)

# config/packages/security.yaml
security:
    encoders:
        App\Entity\User: bcrypt

Entity User Provider

#// config/packages/security.yaml
security:
    # ...

    providers:
        users:
            entity:
                # the class of the entity that represents users
                class: 'App\Entity\User'
                # the property to query by - e.g. username, email, etc
                property: 'username'
                # optional: if you're using multiple Doctrine entity
                # managers, this option defines which one to use
                # manager_name: 'customer'

Authentication & firewalls

A firewall is the process which allow to authenticate your system., (*3)

Only one firewall is used by request. You can use pattern, host or service to identify the firewall to use., (*4)

All real URLs are handled by the main firewall (no pattern key means it matches all URLs). A firewall can have many modes of authentication, in other words many ways to ask the question "Who are you?". Often, the user is unknown (i.e. not logged in) when they first visit your website. The anonymous mode, if enabled, is used for these requests., (*5)

# config/packages/security.yaml
security:
    # ...

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

        main:
            provider: users
            anonymous: lazy
            form_login:
                login_path: home
                check_path: login
                use_referer: true
                default_target_path: dashboard
            logout:
                path: logout

    # ...

Denying access, Roles, and other Authorization

# config/packages/security.yaml
security:
    # ...

    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
    access_control:
        - { path: '^/login', roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: '^/register', roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: '^/$', roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: '^/', roles: ROLE_USER }

Link Profile entity to User entity

You have to specify the User class to use instead of UserInterface., (*6)

# config/packages/doctrine.yaml
doctrine:

    # ...

    orm:

        # ...

        resolve_target_entities:
            amillot\UserBundle\Model\UserInterface: App\Entity\User

Add Mapping information

User mapping


<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="App\Entity\User" table="users">
    </entity>

</doctrine-mapping>

Profile mapping


<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="App\Entity\Profile" table="profiles">
    </entity>

</doctrine-mapping>

The Versions

30/04 2018

dev-master

9999999-dev

Managment User bundle

  Sources   Download

MIT

by Adrien

30/04 2018

0.0.1

0.0.1.0

Managment User bundle

  Sources   Download

MIT

by Adrien