Download the PHP package zhujinkui/auth without Composer

On this page you can find all versions of the php package zhujinkui/auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package auth

Auth

这是一个基于ThinkPHP框架的Auth类库

案例展示

基于ThinkPHP开发呈现权限管理的效果 Image text Image text

安装

composer require zhujinkui/tp5-auth

说明

AUTH(基于用户角色的访问控制),就是用户通过角色与权限进行关联。简单地说,一个用户拥有若干角色,每一个角色拥有若干权限。这样,就构造成“用户-角色-权限”的授权模型。在这种模型中,用户与角色之间,角色与权限之间,一般者是多对多的关系。(如下图) Image text

原理

Auth权限认证是按规则进行认证,在数据库中我们有:

我们在认证规则表中定义权限规则, 在认证用户组表中定义每个用户组有哪些权限规则,在认证用户组授权权限表中定义用户所属的用户组。

举例说明: 我们要判断用户是否有显示一个操作按钮的权限, 首先定义一个规则, 在规则表中添加一个名为 show_button 的规则。然后在认证用户组表添加一个用户组,定义这个用户组有show_button 的权限规则(think_auth_group表中rules字段存得时规则ID,多个以逗号隔开), 然后在用户组明细表定义 UID 为1 的用户 属于刚才这个的这个用户组。

配置

将目录下config/auth.php配置文件复制到TP5框架定义应用目录(默认:application,如修改则填写修改名称即可),例如:application/extra下,如无extra文件,创建一个即可。

数据库建立

建立数据库(例如:system),进入system,复制以下Sql语句执行即可,建议使用MySQL版本5.7,当下数据表默认引擎InnoDB,自5.7版本以后默认默认引擎InnoDB

代码举例使用

建立Base控制器作为所有模块基类

在数据库中添加的节点规则格式为: “模块-控制器名称-方法名称”,Auth类还可以多个规则一起认证 如:

表示 认证用户只要有rule1的权限或rule2的权限,只要有一个规则的权限,认证返回结果就为true 即认证通过。 默认多个权限的关系是 “or” 关系,也就是说多个权限中,只要有个权限通过则通过。 我们也可以定义为 “and” 关系

第三个参数指定为"and" 表示多个规则以and关系进行认证, 这时候多个规则同时通过认证才有权限。只要一个规则没有权限则就会返回false。

Auth认证,一个用户可以属于多个用户组。 比如我们对 show_button这个规则进行认证, 用户A 同时属于 用户组1 和用户组2 两个用户组 , 用户组1 没有show_button 规则权限, 但如果用户组2 有show_button 规则权限,则一样会权限认证通过。

通过上面代码,可以获得用户所属的所有用户组,方便我们在网站上面显示。Auth类还可以按用户属性进行判断权限, 比如按照用户积分进行判断, 假设我们的用户表(think_member)有字段score记录了用户积分。我在规则表添加规则时,定义规则表的condition字段,condition字段是规则条件,默认为空 表示没有附加条件,用户组中只有规则就通过认证。如果定义了condition字段,用户组中有规则不一定能通过认证,程序还会判断是否满足附加条件。比如我们添加几条规则:

这里 {points} 表示 think_members 表 中字段 points 的值。


All versions of auth with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zhujinkui/auth contains the following files

Loading the files please wait ....