ujjwal / auth
该软件包最新版本(1.0.1)没有提供许可信息。
基于 ZfcUser 的 Zend 框架模块,用于检查用户是否已登录以及管理会话、会话保存处理器等。
1.0.1
2014-05-26 06:39 UTC
Requires
- php: >=5.3.3
- zendframework/zendframework: 2.*
- zf-commons/zfc-user: >=0.1,<2.0
This package is auto-updated.
Last update: 2024-09-13 14:14:24 UTC
README
基于 ZfcUser 的 Zend 框架模块,用于检查用户是否已登录以及管理会话、会话保存处理器等。
注意
该模块目前不再维护。请使用 HtSession 代替。
##要求
- Zend Framework 2
- ZfcUser
- ZfcBase
##安装
- 将
"ujjwal/auth": "1.0.*",
添加到您的 composer.json 中,并运行php composer.phar update
- 在
config/application.config.php
中启用该模块 - 将位于
./vendor/ujjwal/auth/config/Auth.local.php
的文件复制到./config/autoload/Auth.local.php
,并根据需要更改值
##选项
查看 config/Auth.local.php
中可用的选项
##特性
- 模块和控制器访问
- 会话配置
- 会话设置保存处理器
- 会话验证器
####模块和控制器访问
使用此模块,您可以限制未经授权的用户访问某些控制器和模块。这可以通过模块选项轻松完成。为此,编辑 Auth.local.php
$auth_settings = array( /** * Log In Modules * * Please set modules where logged in user can only gain access */ 'modules' => array( 'Admin', 'Application', ), /** * Controllers where you can set if user can access or not * * 'controllers' => array( 'include' => array(), // Please set controllers where logged in user can only gain access 'exclude' => array(), // Please set controllers where public user as well as logged in user can gain access // Note that, this part will override above `include` and `modules` ), */ );
会话配置
您可以将所有会话选项(例如会话名称、保存路径、保存处理器等)设置为会话选项。为此,按照以下方式编辑 Auth.local.php
$session_settings = array( /** * Session Config Class * * Name of class used to manage session config options. Useful to create your own * Session Config Class. Default is Zend\Session\Config\SessionConfig. * The class should implement Zend\Session\Config\ConfigInterface. */ //'config_class' => 'Zend\Session\Config\SessionConfig', /** * Session Config Options * * session options such as name, save_path can be set from here * This is the part sent to Session Config Class. Default is empty array. */ 'config_options' => array( 'name' => 'my_application', 'save_path' => 'data/session' ), );
会话设置保存处理器
此模块还附带会话设置保存处理器,用于将会话数据存储在数据库中。默认情况下,session_set_save_hander 已启用。如果希望禁用它,请在以下设置中禁用它
$session_settings = array( /** * Use session save handler or not. * * Default is true. Useful to store session data in database * see https://php.ac.cn/manual/en/function.session-set-save-handler.php * Accept values: true and false */ //'save_handler_or_not' => true, /** * Session Save Handler DI Alias * * Please specify the DI alias for the configured AuthSessionSaveHandler * instance that this module should use. * Default is AuthSessionSaveHandler which is provided by this module. * This class should implement Zend\Session\SaveHandler\SaveHandlerInterface * Note that, if above is false, this will be useless */ //'saveHandler' => 'AuthSessionSaveHandler' );
注意
:不要忘记导入 data/mysql.sql
中可用的模式以使用 session_set_save_handler
会话验证器
您可以轻松设置由 Zend Framework 2 提供的验证器。在配置文件中根据需要更改以下内容
$session_settings = array( /** * Session Validators * * Session validators provide various protection against session hijacking. * see http://framework.zend.com/manual/2.2/en/modules/zend.session.validator.html for more details */ 'validators' => array( 'Zend\Session\Validator\RemoteAddr', 'Zend\Session\Validator\HttpUserAgent', ), );
结语
不要忘记分叉此模块并向我发送 pull request 以使此模块更加完善!