unclexo/xo-user
Composer 安装命令:
composer require unclexo/xo-user
包简介
A ZF2 module for user authentication and managing user sessions in database.
README 文档
README
XOUser is a skeleton module for user authentication and registration for Zend Framework 2. This is for making a user module very fast by extending its available functionality. XOUser stores session data in database. This is mainly a combination of Zend\Db, Zend\Session and Zend\Authentication for managing users persistently.
Version
Please use one of versions from below:
| Supported Zend Framework version |
|---|
| >= 2.2.7 to <= 2.5.0 |
Features
- User login - authenticate via username or email (by specifying one of these two and changing that in other places).
- User registration.
- User change-password.
- Forms protected against CSRF.
Installation
Using composer:
- In your project, use the following command on your terminal.
$ composer require unclexo/xo-user
- Add this
XOUsermodule name in yourapplication.config.phpfile.
<?php return array( 'modules' => array( // ... 'XOUser', ), // ... );
Database Config:
XOUser expects and assumes you have a valid database configuration under a top key named db.
Database Tables:
XOUser expects two database tables named users and session for managing users and sessions respectively:
CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `email` varchar(100) DEFAULT NULL, `username` varchar(100) DEFAULT NULL, `password` varchar(60) DEFAULT NULL, `modifiedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(`id`), KEY `idx_email` (`email`), KEY `idx_username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `users` (`id`, `email`, `username`, `password`, `modifiedAt`, `createdAt`) VALUES (1, 'admin@gmail.com', 'admin', '$2y$10$iMDN8kS81DAdHy9/zNd3we2ChPwhy2bTkVIsCyHpNtaNZl9zUuyxG', '0000-00-00 00:00:00', '0000-00-00 00:00:00'); CREATE TABLE IF NOT EXISTS `session` ( `id` char(32) NOT NULL, `name` char(32) NOT NULL, `modified` int(11) DEFAULT NULL, `lifetime` int(11) DEFAULT NULL, `data` text, PRIMARY KEY (`id`), KEY `idx_name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Session Config:
If you want to set custom configuration for handling session, you should do that under top key session_config. If you do not already have a custom configuration for your session, put the following in ./config/module.config.php:
<?php 'session_config' => array( 'name' => 'session_name', 'use_cookies' => true, 'cookie_lifetime' => 0, 'gc_maxlifetime' => 3600, ),
Usage:
Use the following snippet of code in your controller method to manage login action. For more information, you should check the LoginController's processAction method.
<?php $auth = $this->getAuthService() ->getAdapter() ->setIdentity($data['username']) ->setCredential($data['password']) ->setIdentityType('username'); // This can only be 'username' and 'email' $result = $this->getAuthService()->authenticate(); if ($result->isValid()) { // Do something } else { // Do something }
Next up, just use this over and over again where you need:
<?php if (!$this->getAuthService()->hasIdentity()) { return $this->redirect()->toRoute('auth'); }
Available Routes
/auth /auth/login /auth/signup /auth/change-password /auth/logout
Go to your site: http://yoursite.dev/auth and you should see a login page.
Login
username: admin
password: 12345678
Password Hash Caution
DO NOT CHANGE THE PASSWORD HASH SETTINGS FROM THEIR DEFAULTS unless you have fully understood exactly what and why you are doing!
ZF2 Components
The following ZF2 components are considerably used in XOUser module:
- Zend/Authentication
- Zend/Crypt
- Zend/Db
- Zend/Filter
- Zend/Form
- Zend/InputFilter
- Zend/Json
- Zend/ModuleManager
- Zend/Mvc
- Zend/ServiceManager
- Zend/Session
- Zend/Validator
- Zend/View
License
This ZF2 module released under MIT license.
unclexo/xo-user 适用场景与选型建议
unclexo/xo-user 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 07 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「db」 「zf2」 「session」 「auth」 「zf2-module」 「session-management」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 unclexo/xo-user 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 unclexo/xo-user 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 unclexo/xo-user 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LosLog provides some log utility
Laravel Multiauth package
Secure session middleware for Slim 3 framework
EdpModuleLayouts is very simple Laminas module for making module-specific layouts insanely easy.
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Non-I/O blocking PHP SessionHandler implementation using Nette/Caching with DI Extension for Nette framework
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-26