Giter Site home page Giter Site logo

usher's Introduction

Usher

A Doctrine ACL package for Laravel 5

  • Login with Doctrine User entity
  • User roles
  • User banning
  • User suspending
  • User permissions
  • User last login and last attempt event listeners
  • Role permissions

Installation

Include the service provider in config/app.php

'Brouwers\LaravelDoctrine\DoctrineServiceProvider',
'Maatwebsite\Usher\UsherServiceProvider'

Config

To change the defaults of this package, publish the config:

php artisan vendor:publish --provider="Maatwebsite\Usher\UsherServiceProvider"

Default usage

Out of the box, you can use the ACL system without defining your own entities. However this is not recommended!

Custom usage

For example if you want a Customer and Group entity, you just have to make sure it implements Maatwebsite\Usher\Contracts\Users\User. If you want a faster solution, you can optionally extend the MappedSuperclass Maatwebsite\Usher\Domain\Users\User. *Note that you will have to define the roles relation yourself.

Example with the MappedSuperclass:

use Doctrine\ORM\Mapping as ORM;
use Maatwebsite\Usher\Domain\Users\User;
use Maatwebsite\Usher\Contracts\Users\User as UserInterface;

/**
 * @ORM\Entity(repositoryClass="DoctrineCustomerRepository")
 * @ORM\Table(name="customers")
 * @ORM\HasLifecycleCallbacks()
 */
class Customer extends User implements UserInterface
{
    /**
     * @ORM\ManyToMany(targetEntity="Group", inversedBy="customers")
     * @ORM\JoinTable(name="customer_groups")
     * @var ArrayCollection|\App\Domain\Customers\Entities\Role[]
     */
    protected $groups;
    
    /**
     * Customer Constructor
     */
    public function __construct()
    {
        $this->groups = new ArrayCollection();
    }
    
    /**
     * @return ArrayCollection|\Maatwebsite\Usher\Contracts\Roles\Role[]
     */
    public function getRoles()
    {
        return $this->groups;
    }
  }

Same as with the User MappedSuperclass, you'll have to define the User relation yourself.

/**
 * @ORM\Entity(repositoryClass="DoctrineRoleRepository")
 * @ORM\Table(name="groups")
 * @ORM\HasLifecycleCallbacks()
 */
class Group extends Role implements RoleInterface
{

    /**
     * @ORM\ManyToMany(targetEntity="Customer", mappedBy="groups")
     * @var ArrayCollection|Customer[]
     **/
    protected $customers;

    /**
     * Role Constructor
     */
    public function __construct()
    {
        $this->customers = new ArrayCollection();
    }

    /**
     * @return ArrayCollection|\Maatwebsite\Usher\Contracts\Users\User[]
     */
    public function getUsers()
    {
        return $this->customers;
    }
}

Next you'll have to update the class reference in config/usher.php for the user.entity en role.entity

return [
    'users'  => [
        'entity' => 'Customer'
    ],
    'roles'  => [
        'entity' => 'Group'
    ]
]

Events

Domain Events

Domain Event When
UserGotAssignedToRole $user->assignRole($role)
UserGotBanned $user->ban()
UserGotRemovedFromRole $user->removeRole($role)
UserGotSuspended $user->suspend($minutes)
UserRegistered $user->register()
UserUpdatedProfile $user->update()
RoleWasCreated $role->create()
RoleWasUpdated $role->update()

Event Listeners

Event listeners can be enabled and disabled inside the config. By default the listed listenes are all enabled.

Listener When
SaveLastAttemptDate auth.attempt
CheckIfUserIsBanned auth.attempt
CheckIfUserIsSuspended auth.attempt
SaveLastLoginDate auth.login

usher's People

Contributors

patrickbrouwers avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.