vova07 / yii2-users-module

为 Yii 框架提供用户模块。

安装: 479

依赖: 0

建议者: 0

安全: 0

星标: 24

关注者: 9

分支: 15

开放问题: 7

类型:yii2-extension

0.1.3 2015-02-01 19:42 UTC

This package is not auto-updated.

Last update: 2024-09-10 01:42:11 UTC


README

此模块为您的 yii2 应用程序提供用户管理系统。

安装

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

运行以下命令:

php composer.phar require --prefer-dist vova07/yii2-users-module "*"

或者

"vova07/yii2-users-module": "*"

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

配置

yii2-users-module 添加到每个应用程序配置的 module 部分

'modules' => [
    'users' => [
        'class' => 'vova07\users\Module',
        'requireEmailConfirmation' => false, // By default is true. It mean that new user will need to confirm their email address.
        'robotEmail' => 'my@robot.email', // E-mail address from that will be sent all `users` emails.
        'robotName' => 'My Robot Name', // By default is `Yii::$app->name . ' robot'`.
        'activationWithin' => 86400, // The time before a sent activation token becomes invalid.
        'recoveryWithin' => 14400, // The time before a sent recovery token becomes invalid.
        'recordsPerPage' => 10, // Users pe page.
        'adminRoles' => ['superadmin', 'admin'], // User roles that can access backend module.
    ]
]

添加或编辑 user 组件部分

'user' => [
    'class' => 'yii\web\User',
    'identityClass' => 'vova07\users\models\User',
    'loginUrl' => ['/users/guest/login']  // For frontend app
    // 'loginUrl' => ['/users/admin/login']  // For backend app
]

添加或编辑 authManager 组件部分

'authManager' => [
    'class' => 'yii\rbac\PhpManager',
    'defaultRoles' => [
        'user',
        'admin',
        'superadmin'
    ],
    'itemFile' => '@vova07/rbac/data/items.php',
    'assignmentFile' => '@vova07/rbac/data/assignments.php',
    'ruleFile' => '@vova07/rbac/data/rules.php',
]

运行模块迁移

php yii migrate --migrationPath=@vova07/users/migrations

使用方法

扩展安装后,只需在代码中使用即可

Yii::$app->getModule('users');

默认情况下,将创建一个 superadmin 用户,用户名为 admin,密码为 admin12345

安装后,您将能够访问以下链接(相对于您的网站域名)

前端

  • /users/ - 所有用户页面
  • /users/admin/ - 管理员页面
  • /login/ - 登录页面
  • /logout/ - 登出页面
  • /signup/ - 注册页面
  • /recovery/ - 密码恢复页面
  • /resend/ - 重新发送电子邮件激活令牌
  • /activation/ - 账户激活页面
  • /recovery-confirmation/ - 重置密码页面
  • /my/settings/email/ - 修改电子邮件页面
  • /my/settings/password/ - 修改密码页面
  • /my/settings/update/ - 个人资料更新页面

后端

您需要在配置文件中指定通用路由 '<_m>/<_c>/<_a>' => '<_m>/<_c>/<_a>' 以访问模块操作。

  • /users/admin/login/ - 登录页面
  • /users/admin/logout/ - 登出页面
  • /users/crud/index/ - 所有用户页面
  • /users/crud/view/ - 用户页面
  • /users/crud/create/ - 创建新用户页面
  • /users/crud/update/ - 更新用户页面
  • /users/crud/delete/ - 删除单个用户
  • /users/crud/batch-delete/ - 删除多个用户

依赖