项目作者: livelyworks

项目描述 :
Laravel Routes Authorization Library
高级语言: PHP
项目地址: git://github.com/livelyworks/YesAuthority.git
创建时间: 2017-07-26T10:31:42Z
项目社区:https://github.com/livelyworks/YesAuthority

开源协议:MIT License

下载


YesAuthority


YesAuthority is flexible authorization system for Laravel, It checks the route permission to access a certain portion of the site or application. To add Permissions User-based, Role-based, Conditionally. It uses authority.checkpost middleware for filter permission of current accessing route, Under this middleware checked every permission of the user login.

Installation

Require this package in your composer.json or install it by running:

  1. composer require livelyworks/laravel-yes-authority

Now, insert this line into your config/app.php under the provider array.

  1. LivelyWorks\YesAuthority\YesAuthorityServiceProvider::class

Now, run this command after that config/yes-authority.php and app/Http/Middleware/YesAuthorityCheckpostMiddleware.php files are publish.

  1. php artisan vendor:publish --tag="yesauthority"

Now, insert this line into your app/Http/Kernel.php under the $routeMiddleware array.

  1. 'authority.checkpost' => \App\Http\Middleware\YesAuthorityCheckpostMiddleware::class

Use authority.checkpost middleware for handle permission base routes.

  1. Route::group(['middleware' => 'authority.checkpost'], function () {
  2. // Place all those routes here which needs authentication and authorization.
  3. });

Now, the basic setup is ready you need to configure rules of permissions using config/yes-authority.

Configuration

The structure of permissions given below, but it’s highly recommended to read more on docs`.

  1. [
  2. 'allow' => ['*'], // Allowed permission to user. Priority is less than deny.
  3. 'deny' => ['temp1'], // Deny permission to user. Priority is higher than allow.
  4. ]
  5. canAccess('temp1');
  6. // false

Usage - Helpers

  • canAccess($accessId = null);

    Check the access, By default it check current route and return response in boolean value.

    1. canAccess('temp1');
    2. // true or false
  • canPublicAccess($accessId = null); - Authentication not required

    Check the public access, By default it check current route and return response in boolean value.

  1. canPublicAccess();
  2. // true or false

Usage - Facade

  • YesAuthority::check($accessId = null, $requestForUserId = null)

    Check the access of $accessId, By default it check current route and return response in boolean value, And it can check access of perticular user by passing user id ($requestForUserId) parameter.
    1. YesAuthority::check('temp1');
    2. // true or false
  • YesAuthority::isPublicAccess($accessId = null); - Authentication not required

    Check the access of $accessId, By default it check current route and return response in boolean value.
    1. YesAuthority::isPublicAccess('temp1');
    2. // true or false

Usage - Directives

  • @canAccess($accessId = null);

    Check the access, By default it check current route and return response in boolean value.
    1. @canAccess()
    2. // your logic here.
    3. @endAccess;
  • @canPublicAccess($accessId = null); - Authentication not required

    Check the public access, By default it check current route and return response in boolean value.
    1. @canPublicAccess()
    2. // your logic here.
    3. @endAccess;