itk-dev/user-management-bundle

简化用户管理

安装: 333

依赖: 0

建议: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 9

类型:symfony-bundle


README

安装

composer config repositories.itk-dev/user-management-bundle vcs https://github.com/itk-dev/user-management-bundle
composer require itk-dev/user-management-bundle:dev-master

config/bundles.php 中注册该包

<?php

return [
    …
    ItkDev\UserManagementBundle\ItkDevUserManagementBundle::class => ['all' => true],
];

配置

使用 bin/console config:dump-reference ItkDevUserManagementBundle 查看配置参考。

示例

itk_dev_user_management:
    site_name: '%env(SITE_NAME)%'
    site_url: '%env(SITE_URL)%'

    sender:
        email: '%env(MAILER_EMAIL)%'
        name: '%env(MAILER_NAME)%'

    # Template for mails sent to new users
    user_created:
        subject: '{{ site_name }} – new user created'
        header: 'User created on {{ site_name }}'
        body: |
            <p style='margin: 0;'>
              You have been registered as user on {{ site_name }} with email
              address {{ user.email }}.
            </p>
            <p style='margin: 0;'>
              To get started, you have to choose a password.
            </p>
            <p style='margin: 0;'>
              After choosing a password, you can sign in with your email address
              ({{ user.email }}) and the choosen password.
            </p>
        button:
            text: 'Choose password'
        footer: '<p style="margin: 0;">Best regards,<br/> {{ site_name }}</p>'

    # Set to true to automatically notify users on creation.
    # Otherwise, use the `itk-dev:user-management:notify-users-created` console
    # command or call `UserManager::notifyUserCreated` to notify new users.
    notify_user_on_create: false

配置 FOSUserBundle 并确保使用此包的用户管理器

fos_user:
    
    service:
        user_manager: ItkDev\UserManagementBundle\Doctrine\UserManager
    

命令

bin/console itk-dev:user-management:notify-users-created --help

控制器

为了方便,您可以在 EasyAdminBundle 配置中使用 ItkDev\UserManagementBundle\Controller\UserController

easy_admin:
    entities:
        User:
            class: App\Entity\User
            controller: ItkDev\UserManagementBundle\Controller\UserController

用户角色表单类型

在编辑用户角色时,您可以使用 ItkDev\UserManagementBundle\Form\Type\UserRolesType 获取角色层次结构中的角色列表(仅列出从 options.base_roles 可达的角色,默认为 [ROLE_ADMIN]

easy_admin:
    entities:
        User:
            
            form:
                fields:
                    
                    - property: roles
                      type: ItkDev\UserManagementBundle\Form\Type\UserRolesType
                      # Optionally, specify base roles:
                      type_options:
                          base_roles: [ROLE_ADMIN] # default