ellingham-technologies/phpusersystem

此软件包已被 放弃,并且不再维护。未建议替代软件包。

PHP的用户管理解决方案,简化版。

v0.4.0 2019-05-19 03:52 UTC

This package is auto-updated.

Last update: 2020-02-02 07:10:18 UTC


README

Build Status codecov Latest Stable Version Latest Unstable Version Tested PHP Versions

Ellingham Dev

PHP的用户管理解决方案。可以说这是一个框架。但它只处理用户管理。其余的由您自己处理。

使用PHP 7编写,并利用数据类型进行方法和方法参数。

特性

  • 用户账户(注册、登录、忘记密码功能)
  • 用户资料(面向公众的用户信息)
  • 用户权限(读取、写入、执行、修改、删除 + 自定义权限)
  • 用户限制(类似于权限,但当你需要限制时...)
  • 用户令牌(用于忘记密码、电子邮件验证等)
  • 用户偏好(为您的用户存储偏好!)
  • 用户元数据(为用户存储额外的数据,例如备份电子邮件地址)
  • 管理工具(一套预构建的管理助手)

未来

  • 双因素认证
  • API(用于移动应用等)
  • 数据缓存

我们将标记目前处于开发中的特性

随机示例

use EllinghamTech\Database\SQL\MySQL;
use EllinghamTech\PHPUserSystem\UserSystem;

$database = new MySQL(); // Also support SQLite: new SQLite();
$database->connect($host, $user, $pass, $dbname);

UserSystem::init($database);
$currentUser = UserSystem::session()->user();

请参阅 samples/ 目录以获取有关如何在项目中实现当前特性的详细信息。

数据库支持

目前支持MySQL和SQLite,使用EllinghamTech PHPHelpers中提供的数据库包装器。

如果您已经使用PDO,则不需要创建新的连接。只需使用

use EllinghamTech\PHPUserSystem\UserSystem;

$database = new EllinghamTech\Database\SQL\Wrapper(); // MySQL() for MySQL, SQLite() for SQLite
$database->useExistingConnection($pdoObject);
UserSystem::init($database);

安装

使用Composer

使用Composer(https://getcomposer.org)只需运行

composer require ellingham-technologies/phpusersystem

或将其行添加到composer.json文件的要求部分,并使用composer更新/安装

"ellingham-technologies/phpusersystem": "@stable",

不使用Composer

我们不推荐此选项 我们包含了一个自定义的AutoLoader(src/EllinghamTech/PHPUserSystem/AutoLoad.php),可以用于或您可以选择按需包含类。请注意,此库需要EllinghamTech/PHPHelpers

依赖

  • PHP 7.1或更高版本
  • PDO(支持SQL/MySQL或SQLite)
  • Composer管理

设置

此库需要数据库中特定的一组表。更多详细信息可以在DATABASE.md中找到。必要的CREATE TABLE查询可以在sql/目录中找到。

我们计划在将来构建安装和更新脚本。在此之前,如果表发生变化,您将需要手动进行更改。确保在更新之前阅读发行说明。

工厂、助手和对象初始化

许多对象由工厂或助手实例创建。这减少了设置某些对象时的复杂性。

某些实例是由它们的“父”实例创建的,例如,可以通过在User对象上使用getUserPermission(string $permission_name)方法来创建一个UserPermission

use EllinghamTech\Database\SQL\MySQL;
use EllinghamTech\PHPUserSystem\UserSystem;
use EllinghamTech\PHPUserSystem\UserFactory;

$database = new MySQL(); // Also supports SQLite: new SQLite();
// Already using PDO?
// Then use $database->useExistingConnection($pdo_object_here);
// You can also set the database type with $database->database_type = 'sql';
$database->connect($host, $user, $pass, $dbname);

UserSystem::init($database);

// Create a user object using the factory
$user = UserFactory::newUser(); // Instance of User

$user->user_name = 'NewUser';
$user->user_email = 'example@example.com';
$user->setPassword('a_password_here'); // setPassword will handle password hashing for you

$user->save(); // We now have a new user in the database!

// Loading user with factory
$user = UserFactory::getUserByUserName('NewUser'); // Instance of User

// Loading user permission
$userPermission = $user->getUserPermission('posts'); // Instance of UserPermission

$canModifyPost = $userPermission->hasPermission('m'); // Bool
$canWritePost = $userPermission->hasPermission('w'); // Bool, write = add in this context

// Get a user limit
$userPostLimit = $user->getUserLimit('daily_posts'); // Instance of UserLimit
$canMakeOnePost = $userPostLimit->isWithinLimit(); // Bool
$canMakeTwoPosts = $userPostLimit->isWithinLimit(2); // Bool

if($canMakeOnePost)
{
    // do the post stuff
    $userPostLimit->drawDown(1); // Decreases current limit value by 1
}

UserFactory和所有Helper类仅使用静态方法。这些类可扩展,以适应您的自定义功能。

支持

您可以从https://ellingham.dev/获取支持,或者通过GitHub上的工单来获取。

在1.0版本发布后,我们将提供更多的支持。