Download the PHP package 5ini99/think-auth without Composer

On this page you can find all versions of the php package 5ini99/think-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 think-auth

think-addons

The ThinkPHP5 Auth Package

安装

composer require 5ini99/think-auth

配置

公共配置

导入数据表

think_ 为自定义的数据表前缀

原理

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

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

下面举例说明:

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

使用

判断权限方法

Auth类也可以对节点进行认证,我们只要将规则名称,定义为节点名称就行了。 可以在公共控制器Base中定义_initialize方法

这时候我们可以在数据库中添加的节点规则, 格式为: “控制器名称-方法名称”

Auth 类 还可以多个规则一起认证 如:

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

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

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

通过上面代码,可以获得用户所属的所有用户组,方便我们在网站上面显示。

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

name字段:grade1 condition字段:{score}<100
name字段:grade2 condition字段:{score}>100 and {score}<200
name字段:grade3 condition字段:{score}>200 and {score}<300

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

那么这时候

$auth->check('grade1', uid) 是判断用户积分是不是0-100
$auth->check('grade2', uid) 判断用户积分是不是在100-200
$auth->check('grade3', uid) 判断用户积分是不是在200-300


All versions of think-auth with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.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 5ini99/think-auth contains the following files

Loading the files please wait ....