2017 © Pedro Peláez
 

symfony-bundle user-bundle

Appverk user bundle

image

app-verk/user-bundle

Appverk user bundle

  • Wednesday, June 20, 2018
  • by art4webs
  • Repository
  • 2 Watchers
  • 0 Stars
  • 52 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 24 % Grown

The README.md

Appverk UserBundle documentation v2.0

Simple and lightweight User bundle for Symfony 3 projects. Provides user and role functionalities with ACL support., (*1)

Old version:

If u need help with 1.* branch, visit v1.x documentation., (*2)

Installation:

Required the bundle with composer:, (*3)

~~~~ {.sourceCode .} $ php composer.phar require app-verk/user-bundle, (*4)


Configuration ------------- Register the bundle in your AppKernel.php ~~~~ {.sourceCode .php} // ./app/AppKernel.php public function registerBundles() { $bundles = [ ... new AppVerk\UserBundle\UserBundle(), ... ]; }

Add a new config file, for example user.yml, (*5)

~~~~ {.sourceCode .yaml}, (*6)

./app/config/user.yml

user: entities: user_class: #E.g. AppBundle\Entity\User, (*7)

 acl: 
    enabled:       #true|false defines to use or not to use ACL
    access_denied_path: #route bame where user should be redirect when he dont have privileges to action
Import user.yml file to config.yml

~~~~ {.sourceCode .yaml}
imports:
...
- { resource: user.yml }

Next create two entities in your bundle (E.g. AppBundle\Entity):, (*8)

  • User

~~~~ {.sourceCode .php} <?php, (*9)

namespace AppBundle\Entity;, (*10)

use AppVerk\UserBundle\Entity\User as AbstractUser; use Doctrine\ORM\Mapping as ORM;, (*11)

/** * * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") */ class User extends AbstractUser implements EntityInterface { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; }, (*12)


*You can use configuration format which you prefer (yml, xml, php or annotation)* Run
php bin/console doctrine:schema:update --force

Now You can create admin user with command line:
php bin/console user:create:admin <username> <email> <password>

ACL --- Enable ACL ~~~~ {.sourceCode .yaml} #./app/config/user.yml user: acl enabled: true access_denied_path: #route name

Use annotation to define protected action, (*13)

// ./src/AppBundle/Controller/DefaultController.php

...
use AppVerk\UserBundle\Annotation\AVSecurity;
...

    /**
     * ...
     * @AVSecurity(allow={"ROLE_ADMIN"}, disallow={"ROLE_X"}, name="list", group="default")
     */
    public function listAction()
    {
        return $this->render('@App/controller/user/list.html.twig');
    }

Custom AccessResolver

In some cases u need to create your own logic to decide about access to action. In that case u just need to create custom accessResolver and put your logic, (*14)

// ./src/AppBundle/Security/CustomAccessResolver.php

...
use AppVerk\UserBundle\Security\AccessResolverInterface;
...

class SimpleAccessResolver implements AccessResolverInterface
{
    public function resolve(RoleableInterface $user, $action): bool
    {
    // your own logic
    }
}

Insert new resolver to configuration file: ~~~~ {.sourceCode .yaml}, (*15)

./app/config/user.yml

user: entities: user_class: #E.g. AppBundle\Entity\User, (*16)

 acl: 
    enabled:       #true|false defines to use or not to use ACL
    access_denied_path: #route bame where user should be redirect when he dont have privileges to action
    access_resolver_class: AppBundle\Security\CustomAccessResolver

~~~~, (*17)

The Versions