2017 © Pedro Peláez
 

library authorization

Authorization, Authentication, Acl

image

trejjam/authorization

Authorization, Authentication, Acl

  • Monday, April 18, 2016
  • by trejjam
  • Repository
  • 1 Watchers
  • 0 Stars
  • 848 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 17 Versions
  • 0 % Grown

The README.md

Authorization

Latest stable, (*1)

Library for, (*2)

  • authorization
  • roles
  • resource

in Nette using database, (*3)

Installation

The best way to install Trejjam/Authorization is using Composer:, (*4)

$ composer require trejjam/authorization

Configuration

.neon, (*5)

extensions:
    authorization: Trejjam\Authorization\DI\AuthorizationExtension

authorization:
    tables:
        users:
            table    : users__users
            id      : id #column name
            status    : 
                accept : enable 
                options:
                    enable
                    disable
            activated : 
                accept: yes    
                options:
                    yes
                    no
            username  : 
                match  : '/^[a-zA-Z_]+$/' #email is special value (validate by Nette\Utils\Validators:isEmail)
                length : 60
            items:
                - id
                - status
                - activated
                - username
                - password
                dateCreated: date_created
        roles:
            table    : users__roles
            id       : id #column name
            parentId : parent_id #column name, foreign key to role.id
            roleName : name #column name
            info     : info #column name, value FALSE disable usage        
        userRoles:
            table  : users__user_role
            id     : id #column name
            userId : user_id #column name, foreign key to users.id
            roleId : role_id #column name, foreign key to roles.id
        resource : 
            table          : users__resources
            id             : id #column name
            roleId         : role_id #column name, foreign key to role.id
            resourceName   : name #column name
            resourceAction : action #column name, default ALL
    reloadChangedUser: true
    cache : 
        use     : true
        name    : authorization
        timeout : 10 minutes    
    debugger:false #not implemented yet

services:
    - Browser

Config

The best way for configuration is using Kdyby/Console, (*6)

$ composer require kdyby/console

Read how to install Kdyby/Console, (*7)

php index.php

After successful installation display:, (*8)

Available commands:
Auth
    Auth:install    Install default tables
    Auth:resource   Edit resource
    Auth:role       Edit role
    Auth:user       Edit user
    help            Displays help for a command
    list            Lists commands

Config database

Create default tables:, (*9)

php index.php Auth:install

Config role

Add role:, (*10)

php index.php Auth:role -c [-r] roleName [parentRole [info]]

Move role to other parent:, (*11)

php index.php Auth:role -m [-r] roleName [parentRole]

Delete role: options -f delete all child roles and their resource, (*12)

php index.php Auth:role -d [-f] roleName

List all role:, (*13)

php index.php Auth:role -r

Config resource

Add resource:, (*14)

php index.php Auth:resource -c [-r] resourceName[:resourceAction] parentRole

Move resource to other role:, (*15)

php index.php Auth:resource -m [-r] resourceName[:resourceAction] parentRole

Delete resource:, (*16)

php index.php Auth:resource -d resourceName[:resourceAction]

List all resource:, (*17)

php index.php Auth:resource -r

Config user

Add user:, (*18)

php index.php Auth:user -c username password

Change password:, (*19)

php index.php Auth:user -p username password

Set user status:, (*20)

php index.php Auth:user -s status username

default status values [enable|disable], (*21)

Set user activated:, (*22)

php index.php Auth:user -a activated username

default activated values [yes|no], (*23)

Show user roles:, (*24)

php index.php Auth:user -r username

Add user role:, (*25)

php index.php Auth:user [-r] -t roleName username

Remove user role:, (*26)

php index.php Auth:user [-r] -d roleName username

Usage

Presenter:, (*27)

    /**
    * @var \Trejjam\Authorization\Acl @inject
    */
    public $acl;
    /**
    * @var \Trejjam\Authorization\UserManager @inject
    */
    public $userManager;
    /**
    * @var \Trejjam\Authorization\UserRequest @inject
    */
    public $userRequest;

    function renderDefault() {
        dump($this->acl->getTrees()->getRootRoles()); //get all roles without parent
        dump($this->acl->getTrees()->getRoles()); //get all roles
        dump($this->acl->getTrees()->getResources()); //get all resource

        $this->acl->createRole($name, $parent, $info);
        $this->acl->deleteRole($name);
        $this->acl->moveRole($name, $parent);

        dump($this->acl->getRoleByName($roleName)); //return AclRole with "name"

        $this->acl->createResource($name, $action, $roleName);
        $this->acl->deleteResource($name, $action);
        $this->acl->moveResource($name, $action, $roleName);

        dump($this->acl->getResourceById($id)); //return AclResource

        dump($this->acl->getUserRoles($userId)); //return AclRole[] 
        $this->acl->addUserRole($userId, $roleName);
        $this->acl->removeUserRole($userId, $roleName);

        //--------------userManager--------------

        $this->userManager->add($username, $password);
        $this->userManager->changePassword($username, $password, $type = "username"); //$type could be username|id
        $this->userManager->setUpdated($username, $type = "username"); //next user request user session will be reload (if "reloadChangedUser: true")
        $this->userManager->setStatus($username, $status, $type = "username"); //$status could be enable|disable - if user with disable status try login, login function return exception
        $this->userManager->setActivated($username, $activated = NULL, $type = "username"); //$activated could be yes|no - if user with 'no' activated try login, login function return exception
        dump($this->userManager->getUserId($username)); //return id of user
        $this->userManager->getUserInfo($username, $type = "auto"); //return all information about user except password
        $this->userManager->getUsersList(); //return getUserInfo[] for all users

        //--------------userRequest--------------

        dump($this->userRequest->generateHash($userId, $type)); //return hash for public usage, $type could be activate|lostPassword 
        dump($this->userRequest->getType($userId, $hash, $invalidateHash = FALSE)); //return TRUE - hash was used|$type|FALSE - user hasn't this hash, $invalidateHash=TRUE - disable future hash usage
    }

The Versions

18/04 2016
27/09 2015
27/09 2015

v0.10.0

0.10.0.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

29/06 2015

v0.8.3.5

0.8.3.5

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

10/06 2015

v0.8.3.4

0.8.3.4

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

01/03 2015

v0.8.3.2

0.8.3.2

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

18/02 2015

v0.8.3.1

0.8.3.1

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

18/02 2015

v0.8.3

0.8.3.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

18/02 2015

v0.8.2

0.8.2.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

17/02 2015

v0.8.1

0.8.1.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

16/02 2015

v0.8

0.8.0.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

09/02 2015

v0.7

0.7.0.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

15/01 2015

v0.6

0.6.0.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

13/01 2015

v0.5.2

0.5.2.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

12/01 2015

v0.5.1

0.5.1.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

11/01 2015

v0.5

0.5.0.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette

16/12 2014

v0.4

0.4.0.0

Authorization, Authentication, Acl

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Trejbal

authentication authorization acl nette