elzix / yii2-auth
Yii 2 用户认证 & 基于角色的访问控制 (RBAC) 模块
dev-master
2024-05-17 11:02 UTC
Requires
- php: >=8.1.0
- yiisoft/yii2: *
- yiisoft/yii2-bootstrap5: *
- yiisoft/yii2-composer: *
- yiisoft/yii2-swiftmailer: *
This package is auto-updated.
Last update: 2024-09-17 11:47:49 UTC
README
Auth 模块是一个灵活的用户注册、认证和 RBAC 模块,适用于 Yii2。它为您的 Yii2 网站提供用户认证、注册和 RBAC 支持。
致敬
本项目是从 robregonm/yii2-auth 分支出来的。基本功能相同,但已对代码进行了修改,以使其与 Yii2 v2.0.49.3 兼容。
安装
安装此扩展的最佳方式是通过 composer。
运行以下命令:
$ php composer.phar require elzix/yii2-auth:dev-master
或者
"elzix/yii2-auth": "dev-master"
将以下内容添加到您的 composer.json
文件的 require 部分中。
用法
安装扩展后,修改您的应用程序配置以包含
return [ 'modules' => [ ... 'auth' => [ 'class' => 'auth\Module', // Custom layouts // Alternative: @common/views/layouts/main 'layout' => '//homepage', // Layout when not logged in yet 'layoutLogged' => '//main', // Layout for logged in users // Custom views (optional) // 'loginTemplate' => '', // 'signupTemplate' => '', // 'requestTemplate' => '', // 'resetTemplate' => '', // 'profileTemplate' => '', // 'profileUpdateTemplate' => '', // 'userTemplate' => '', // 'userViewTemplate' => '', // 'userCreateTemplate' => '', // 'userUpdateTemplate' => '', 'attemptsBeforeCaptcha' => 3, // Optional 'supportEmail' => 'support@mydomain.com', // Email for notifications 'passwordResetTokenExpire' => 3600, // Seconds for token expiration 'superAdmins' => ['admin'], // SuperAdmin users 'signupWithEmailOnly' => false, // false = signup with username + email, true = only email signup 'db' => 'db', // Optional, database to use 'tableMap' => [ // Optional, but if defined, all must be declared 'User' => 'user', 'UserStatus' => 'user_status', 'ProfileFieldValue' => 'profile_field_value', 'ProfileField' => 'profile_field', 'ProfileFieldType' => 'profile_field_type', ], /** * Custom redirects (optional) * * true = Go Home * false = Go Back * string = Redirect to link */ // 'loginRedirect' => '', // After login // 'passwordRedirect' => '', // After password reset or request // 'signupRedirect' => '', // After signup ], ... ], ... 'components' => [ ... 'authManager' => [ 'class' => '\yii\rbac\DbManager', 'ruleTable' => 'AuthRule', // Optional 'itemTable' => 'AuthItem', // Optional 'itemChildTable' => 'AuthItemChild', // Optional 'assignmentTable' => 'AuthAssignment', // Optional ], 'user' => [ 'class' => 'auth\components\User', 'identityClass' => 'auth\models\User', // or replace to your custom identityClass 'enableAutoLogin' => true, ], ... ] ];
并运行迁移
$ php yii migrate/up --migrationPath=@auth/migrations
许可证
Auth 模块在 BSD-3 许可证下发布。有关详细信息,请参阅附带文件 LICENSE.md
。
# 安装
./yii migrate/up --migrationPath=@auth/migrations
URLs
- 登录:
yourhost/auth/default/login
- 注销:
yourhost/auth/default/logout
- 注册:
yourhost/auth/default/signup
- 重置密码:
yourhost/auth/default/reset-password
- 用户管理:
yourhost/auth/user/index
- 用户资料:
yourhost/auth/profile/view