ohhink/rrm
Composer 安装命令:
composer require ohhink/rrm
包简介
Laravel RBAC based on Laravel-Permission with backend UI
README 文档
README
This Package is used for rules controller which based on roles
This package is based on Laravel Permission and can build a rule controller panel with UI in few minutes.
Server Requirements:
- Php >= 7.2
- Laravel Version >= 6.1 && < 7.0 (Not Support for Laravel Version >= 7.0 , will update soon)
what include
Const
The rule in this novel can be regards as route in Laravel
Why I do this
Word is cheap , show me the code !
Laravel Permission is a very good package without UI. So, this package is add UI on the laravel permission package and do some things to make the panel can be built quickly
What Include:
- Rule controller based on Role , you can add more than one roles to a user .
- Add more than one rules to a role .
- Menus can be different as it depends on the rules the user have .
- Write your new rules in the
routes/web.phpand it can be add in the program through one button - Record the operation, you can choose to use job to do it sync/async
- Backend ui panel
- Google Authenticator
Installation
Recommend to use new Laravel Project Remember to open
exec,shell_exec,proc*functions inphp.ini
Update the local configure file .env
# change database and key # change cache CACHE_DRIVER=redis REDIS_CLIENT=predis # suggest QUEUE_CONNECTION=redis # google authenticator GOOGLE_AUTHENTICATOR=false
Run the command in the root of your new laravel project with composer
$ composer require ohhink/rrm
Publish the files , which include admin.php,filesystems.php,permission.php and front resource files and database seeds files
$ php artisan vendor:publish
# if you want to reload latest package seeder, run this command in force. It will remove the origin seeder , so please be careful
$ php artisan vendor:publish --tag=seeds --force
Build the database and run the seeder
# run autoload first to update the userseeder
$ composer dump-autoload
$ php artisan migrate:refresh --seed
$ php artisan db:seed --class=RrmDatabaseSeeder
Give folder right and soft-link
$ chmod -R 777 storage $ php artisan storage:link
If you want to use Google Authenticator, you have to add this provider and aliases by yourself
// config/app.php 'providers' => [ //........ Earnp\GoogleAuthenticator\GoogleAuthenticatorServiceprovider::class, SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class, ], 'aliases' => [ //.......... 'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class ],
That's it !
How to use
-
The default of the backend route is
/admin, this can be change though theconfig/admin.phpThe seeder have already make a super admin user , which account is belowaccount : admin@gmail.com password : admin&%@cv..
-
What's RBAC talk about is , assign one or more rules to a role and assign one or more roles to a user. We can controller rules with a role , which we normally do rather than a detail rule. So , there is few steps you have to do with your business logic
- finish your code and add your routes in the route/web.php like you normally do
- click the Route Reload . For example , we get the new route admin.test
- create or update your translate files in the path resources/vendor/rrm/zh-cn/permission.php
- assign this new route to a role , like admin
- if this new route is a menu function, you should create a new menu and rebuild the menu otherwise the new menu will not display
-
If you want to rewrite the route , you should add below to you route/web.php
# this is rewrite the route to your app/Http/Controllers/IndexController.php index() Route::prefix(config('admin.prefix'))->middleware([ 'auth', 'admin' ])->name('admin.')->group(function () { Route::get('/', 'IndexController@index')->name('index'); });In your app/Http/Controllers/IndexController.php file ,you should add below
public function index() { // put your code here !!! // recover the view in /resources/views/vendor/rrm/admin/index.blade.php // OR you can just run command below, it will create blade files automatically // php artisan vendor:publish --tag=views --force return view('rrm::admin.index'); } -
To see the online-user in the right bar , you have to add command in the app/Console.Kernel.php file, like this
protected function schedule(Schedule $schedule) { // $schedule->command('inspire') // ->hourly(); $schedule->command('admin-tool:cache-online-users')->everyMinute(); }And Remember To Add Command In Your Server
* * * * * php /home/vagrant/blade_package/artisan schedule:run >> /dev/null 2>&1 -
Since it record every step user did on panel, if you want to do it async, you can change the key val
QUEUE_CONNECTION=syncin.envfiles toQUEUE_CONNECTION=redisThis will make the recorder use jobs to async log the operations which will be faster. Of course you have to add Redis or PRedis package first -
If you want to change 500 page, you can create a resource/views/vendor/rrm/500.blade.php to rewrite that.
-
Listen Queue Command
php artisan queue:work --queue=logs --sleep=3 --tries=3 # prefer to use supervisor # supervisor config file -- laravel-worker.conf [program:logs] process_name=%(program_name)s_%(process_num)02d command=php path_to/artisan queue:work --queue=logs --sleep=3 --tries=3 autostart=true autorestart=true user=root numprocs=2 redirect_stderr=true stdout_logfile=path_to/supervisor/logs.log save and run ** supervisorctl reload ** to reload it -
The layout of this package, you can use it though the follow code.
@extends('rrm::admin.layout') @section('content') <section id="main-content"> <section class="wrapper"> @if (Session::has('success')) @include('rrm::admin.layout.success',['msg'=>Session::get('success')]) @endif @if (Session::has('error')) @include('rrm::admin.layout.error',['msg'=>Session::get('error')]) @endif <div class="row"> <div class="col-lg-12"> </div> </div> </section> </section> @endsection @section('js') @endsection @section('css') @endsection -
Use Google Authenticator
# First , add config to the file .env GOOGLE_AUTHENTICATOR=true # After that, no matter which page the user going to visit , he will redirect to GOOGLE AUTHENTICATOR PAGE. # Follow the step and it will redirect to the normal page after register. # If you what to vertify in your code , you can learn from the fake code. public function index() { // $google code which is registered before // $vertify code to be verified if (\OhhInk\Rrm\Model\Google::CheckCode($google, $vertify)) { // pass } else { // fail } }
Related Efforts
- Laravel Permission - Associate users with permissions and roles
Maintainers
Contributing
Feel free to dive in! Open an issue or submit PRs.
Standard Readme follows the Contributor Covenant Code of Conduct.
License
MIT © OhhInk
ohhink/rrm 适用场景与选型建议
ohhink/rrm 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 124 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「laravel」 「permission」 「roles」 「permissions」 「rbac」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ohhink/rrm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ohhink/rrm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ohhink/rrm 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provide a way to secure accesses to all routes of an symfony application.
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
It's a barebone security class written on PHP
This package provides a flexible way to add Role-based Permissions to Laravel
Contao CMS integrity check for some files
A PHP security linter to detect insecure functions like var_dump, print_r, and other dangerous functions in your codebase
统计信息
- 总下载量: 124
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-06