johnparra/yii2-auth

Yii 2 用户认证 & 基于角色的访问控制 (RBAC) 模块,robregon 的分支

安装: 12

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 37

开放问题: 0

类型:yii2-extension

0.6.3 2016-07-23 18:59 UTC

This package is not auto-updated.

Last update: 2024-09-26 02:36:18 UTC


README

认证模块是一个灵活的用户注册、认证和 RBAC 模块,适用于 Yii2。它为您的 Yii2 网站提供用户认证、注册和 RBAC 支持。

安装

通过 composer 安装此扩展是首选方式。

运行以下命令

$ php composer.phar require johnparra/yii2-auth "*"

或者将以下内容添加到您的 composer.json 文件的 require 部分中。

"johnparra/yii2-auth": "*"

使用

扩展安装完成后,修改您的应用程序配置以包括

文件 config/web.php

return [
	'modules' => [
	    ...
	        'auth' => [
	            'class' => 'auth\Module',
	            'layout' => '//homepage', // Layout when not logged in yet
	            'layoutLogged' => '//main', // Layout for logged in users
	            '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
	            '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',
	            ],
	        ],
	    ...
	],
	...
	'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,
		],
	    ...
	]
];

文件 config/console.php

    'components' => [
        'authManager' => [
            'class' => 'yii\rbac\DbManager'
        ],
        'user' => [
            'class' => 'auth\components\User',
        ],
        'db' => $db,
    ],

    'modules' => [
        'auth' => [
                'class' => 'auth\Module',
                'superAdmins' => ['admin'], // SuperAdmin users
        ],
    ],

并运行迁移

$ php yii migrate/up --migrationPath=@auth/migrations

许可证

认证模块在 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