germania-kg/user-profiles
Composer 安装命令:
composer require germania-kg/user-profiles
包简介
README 文档
README
Installation
$ composer require germania-kg/user-profiles:^2.0
MySQL users may install the table users using users.sql.txt in sql/ directory.
A. Register a new User
Wraps all necessary tasks in a single Callable.
For a detailed list of all single tasks, see chapters below.
- Check if login name is available
- Insert new User
- Set user's password
- Set user's API Key
Please note that just registration will not mark the new user as active. By default, he will be marked as inactive as desribed in MySQL table scheme. See section B. Set users 'active' state for details.
If the registration fails for some reason, a RegisterUserException will be thrown.
<?php use Germania\UserProfiles\RegisterUserWrapper; use Germania\UserProfiles\Exceptions\RegisterUserException; $pdo = new PDO( ... ); $hash = function() { return ... ; }; $rnd = function() { return ... ; }; $logger = new Monolog(); $users_table = 'users'; $users_roles_table = 'users_roles'; // Setup callable $register = new RegisterUserWrapper( $pdo, $hash , $rnd, $users_table, $users_roles_table, $logger); // User data $user_data = [ 'first_name' => 'John', 'last_name' => 'Doe', 'display_name' => 'John Doe', 'email' => 'john@test.com', 'login' => 'john@test.com' ]; $roles = [1, 22]; // Store new user try { $user_id = $register( $user_data, $roles ); } catch (RegisterUserException $e) { echo "Failed: ", $e->getMessage(); }
1. Check if login name is available
Return TRUE if the given login name is available, FALSE otherwise.
<?php use Germania\UserProfiles\PdoUsernameChecker; use Germania\UserProfiles\Exceptions\LoginNameNotAvailableException; $pdo = new PDO( ... ); $logger = new Monolog(); $table = 'users'; try { $lookup = new PdoUsernameChecker( $pdo, $logger, $table); $available = $lookup( 'johndoe_224' ); } catch (LoginNameNotAvailableException $e) { // Login name not available, someone else using it? }
2. Insert new User
Throws a UserProfileException if required user data fields are missing.
<?php use Germania\UserProfiles\PdoInsertNewUser; use Germania\UserProfiles\Exceptions\InsertUserException; $pdo = new PDO( ... ); $logger = new Monolog(); $table = 'users'; try { $inserter = new PdoInsertNewUser( $pdo, $logger, $table); $new_id = $inserter([ 'first_name' => 'John', 'last_name' => 'Doe', 'display_name' => 'John Doe', 'email' => 'john@test.com', 'login' => 'john@test.com' ]); } catch (InsertUserException $e) { // Hmmm. Could not insert new User? // Maybe some fields missing? }
3. Set a Users' Password
<?php use Germania\UserProfiles\PdoPasswordSetter; use Germania\UserProfiles\Exceptions\SetPasswordException; $pdo = new PDO( ... ); $hash = function() { return 'ABCDEF'; }; $logger = new Monolog(); $table = 'users'; $user = 42; try { $setter = new PdoPasswordSetter( $pdo, $hash, $logger, $table); $result = $setter( 42, 'top_secret' ); } catch (SetPasswordException $e) { // Could not change user's apssword?! }
4. Set a User's API Key
<?php use Germania\UserProfiles\PdoApiKeySetter; use Germania\UserProfiles\Exceptions\SetApiKeyException; $pdo = new PDO( ... ); $rnd = function() { return 'ABCDEF'; }; $logger = new Monolog(); $table = 'users'; try { $setter = new PdoApiKeySetter( $pdo, $random_gen, $logger, $table); $result = $setter( 42 ); } catch (SetApiKeyException $e) { // Could not set new API key. }
B. Set users 'active' state
<?php use Germania\UserProfiles\PdoSetActiveState; use Germania\UserProfiles\Exceptions\SetActiveStateException; $pdo = new PDO( ... ); $hash = function() { return 'ABCDEF'; }; $logger = new Monolog(); $table = 'users'; $user = 42; try { $setter = new PdoSetActiveState( $pdo, $logger, $table); $result = $setter( 42, PdoSetActiveState::ACTIVE ); $result = $setter( 42, PdoSetActiveState::INACTIVE ); } catch (SetActiveStateException $e) { // Could not change active state?! }
C. Update user profile
Throws a UserProfileException if required user data fields are missing.
<?php use Germania\UserProfiles\PdoProfileUpdater; use Germania\UserProfiles\Exceptions\UpdateProfileException; $pdo = new PDO( ... ); $logger = new Monolog(); $table = 'users'; $user = 42; try { $updater = new PdoProfileUpdater( $pdo, $logger, $table); $result = $updater( $user, [ 'first_name' => 'John', 'last_name' => 'Doe', 'display_name' => 'John Doe', 'email' => 'john@test.com', 'login_name' => 'john@test.com' ]); } catch (UpdateProfileException $e) { // Could not update the user's profile }
D. Validate a user's credentials:
Check if login name and password match a stored user:
<?php use Germania\UserProfiles\PdoCredentialsValidator; $pdo = new PDO( ... ); $verifier = function() { return false; }; $logger = new Monolog(); $table = 'users'; $checker = new PdoCredentialsValidator( $pdo, $verifier, $logger, $table); $result = $checker( 'joehndoe@test.com', 'take_this_secret' ); if ($result) { // valid } else { // Password and/or Login name are invalid! }
Issues
See issues list.
Development
$ git clone https://github.com/GermaniaKG/UserProfiles.git
$ cd UserProfiles
$ composer install
Unit tests
Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
$ composer test # or $ vendor/bin/phpunit
germania-kg/user-profiles 适用场景与选型建议
germania-kg/user-profiles 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 119 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 germania-kg/user-profiles 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 germania-kg/user-profiles 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 119
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-15