skylineos / yii.user
独立的用户模块,包含登录、重置、管理等功能
Requires
- php: >=7.4
- yiisoft/yii2: >=2.0.41
Requires (Dev)
- codeception/assert-throws: *
- codeception/codeception: *
- codeception/module-asserts: ^1.0.0
- codeception/module-db: *
- codeception/module-phpbrowser: ^1.0.0
- codeception/module-yii2: *
- nathanmac/datetime-codeception-module: ~1.0
- phpunit/php-code-coverage: *
- squizlabs/php_codesniffer: *
- yiisoft/yii2-bootstrap4: ~2.0.6
- yiisoft/yii2-debug: ~2.1.0
- yiisoft/yii2-swiftmailer: *
This package is auto-updated.
Last update: 2024-09-08 17:35:34 UTC
README
为Yii框架提供创建、更新、查看和删除认证用户的扩展
安装
将仓库条目添加到compose.json
文件中
{
"type": "vcs",
"url": "git@gitlab.skyts.io:csg/yii/yii2-user.git"
}
将条目添加到compose.json
文件的required
属性中
"skyline/yii.user": "[version]"
其中[版本]是此扩展的版本。
Yii兼容性
配置
在您的配置文件(通常是config/web.php
)中添加以下条目
components' => [
// ... other components ...
'user' => [
'identityClass' => 'skyline\yii\user\models\User',
'enableAutoLogin' => true,
],
],
'modules' => [
// ... other modules ...
'user' => [
// Required Parameters
'class' => 'skyline\yii\user\Module',
'defaultRoute' => 'UserController',
/**
* Optional settings
*/
// Where to redirect after logging in/handling auth sessions
'homeRedirect' => '/cms',
// How long the password reset token should last (eg. today + x time)
// @see https://php.ac.cn/strtotime
'passwordResetTokenExp' => '+5 days',
// How long the remember me should function
'rememberMeExpiration' => 3600 * 24 * 30,
// If you want to override the default layout
// If you want to use the default layout within the module, set this
// to '@vendor/skylineos/yii.user/views/layouts/login'
'layout' => '@app/.../views/layouts/<layout>'
/**
* If you want to override the views folder. It will look for a folder 'users' in whatever you specify,
* so, don't add 'user' to your path. Once you've run the migration, you can use gii/crud to generate the
* views for you in your specified namespace (super helpful if you have a template registered with gii)
*/
'viewPath' => '@app/.../views/'
],
]
同时添加一个route
规则指向用户视图/控制器
"components" => [...],
"modules" => [
// ... other modules ...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'/cms/login' => '/user/user/login',
'/cms/' => '/cms/index',
'/cms/users/<action>' => '/user/user/<action>',
'/cms/users/' => '/user/user',
'/' => '/',
'<slug:.*>' => '/site/render'
],
],
// ... other modules ...
]
在您的config/console.php
中添加此模块命令的路由(如果您想使用它们)
'bootstrap' => [
// ... other bootstrap components ...
'user'
],
'modules' => [
// ... other modules ...
'user' => [
'class' => 'skyline\yii\user\Module',
],
],
参数
将以下参数添加到配置文件的params
键中
'supportEmail' => '<email address>',
'supportEmailDisplayName' => 'Skyline Dude',
'passwordRecoverySubject' => 'Forgot your password?',
'newUserEmailSubject' => 'Please finish setting up your account',
迁移
为了确保您的数据库正确设置,您需要运行扩展中的迁移
php yii migrate/up --migrationPath=@vendor/skylineos/yii.user/migrations
如果迁移出现问题,使用以下命令删除任何悬而未决的更改
php yii migrate/down --migrationPath=@vendor/skylineos/yii.user/migrations
依赖
skyline\yii\metronic: >=1.0.0
(通过git@gitlab.skyts.io:csg/yii/yii2.module.metronic.git
仓库条目访问)aws/aws-sdk-php: *
,用于邮件(对于posix已弃用)
测试(单元和功能测试)
此软件包包含配置和docker-compose,以便轻松测试。Docker-compose将为您提供访问PHP扩展、xdebug(用于代码覆盖率)、composer(将安装您的依赖项)和用于功能测试的数据库。
- docker-compose build 仅在首次运行或修改Dockerfile时必要
docker-compose up -d
docker-compose exec php bash
运行测试
假设您已进入php容器并在/app目录下
./vendor/bin/codecept run
./vendor/bin/codecept --help
测试分支
如果您觉得需要或认为这是一个好主意(确实如此),请从develop
分支分支。否则,对于较小的更新,请确保在develop
分支上完成所有工作。您应提交合并请求。
测试提示和技巧
团队主要使用VSCode,建议您也这样做。如果您发现任何扩展或工作流程非常有帮助,请随时添加到这里。