vanio/vanio-user-bundle

Symfony2 Bundle,集成了FOSUserBundle和HWIOAuthBundle,并增加了额外功能和合理的默认设置

v0.3.0 2018-09-14 03:46 UTC

README

Build Status PHP7.1 License

这是一个整合了FOSUserBundle和HWIOauthBundle的Symfony2 Bundle,增加了额外功能和合理的默认设置。

安装

可以使用Composer进行安装,通常的操作是:composer require vanio/vanio-user-bundle

如果您想支持通过社交账户进行认证,可以选择安装HWIOAuthBundle。操作如下:composer require php-http/guzzle6-adapter php-http/httplug-bundle hwi/oauth-bundle

下一步是将此Bundle及其依赖的Bundle注册到您的AppKernel中。

// app/AppKernel.php
// ...

class AppKernel extends Kernel
{
    // ...

    public function registerBundles(): array
    {
        $bundles = [
            // ...
            new FOS\UserBundle\FOSUserBundle,
            new Http\HttplugBundle\HttplugBundle, // Optional, dependency of HWIOAuthBundle
            new HWI\Bundle\OAuthBundle\HWIOAuthBundle, // Optional
            new Vanio\UserBundle\VanioUserBundle,
            new Vanio\UserBundle\VanioWebBundle,
        ];

        // ...
    }
}

默认配置

firewall_name: ~ # firewall name, auto-detected from security configuration when empty
email_only: false # whether to completely omit username and use email only
custom_storage_validation: false # whether to disable predefined uniqueness validation
use_flash_notifications: true # whether to enable notifications using flash messages (notify also on login and logout as an addition to FOSUserBundle)
registration_target_path: ~ # target path used for redirection after completed registration instead of default static pages
pass_target_path: # whether to pass referer in URL query parameter and use it as target path
    enabled: false
    default_target_path: / # default value when target path is not present, default_target_path option inside security configuration is ignored
    target_path_parameter: _target_path: # name of the parameter
    ignored_routes: [] # route names to ignore
    ignored_route_prefixes: # route name prefixes to ignore, the default ones are always merged in
        - fos_user_security_
        - fos_user_registration_
        - fos_user_resetting_
        - hwi_oauth_

social_authentication: ~ # whether to enable social authentication, automatically enabled when HWIOAuthUserBundle is installed
social_registration_form: # social registration form configuration
    type: Vanio\UserBundle\Form\SocialRegistrationFormType # form type
    name: hwi_oauth_registration_form # form name
    validation_groups: [SocialRegistration] # form validation groups

所有这些值都可以作为容器参数使用。它们使用vanio_user.前缀进行命名。
此Bundle根据这些配置值预设了SecurityBundle、FOSUserBundle和HWIOAuthBundle的一些默认值,以简化配置。

默认预设的值包括:

security:
    encoders:
        FOS\UserBundle\Model: bcrypt
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username # or fos_user.user_provider.username_email when %vanio_user.email_only%

fos_user:
    firewall_name: %vanio_user.firewall_name%
    use_listener: false
    use_flash_notifications: %vanio_user.use_flash_notifications%
    registration:
        form:
            type: FOS\UserBundle\Form\Type\RegistrationFormType # or Vanio\UserBundle\Form\EmailOnlyRegistration when %vanio_user.email_only%
        confirmation:
            template: VanioUserBundle:Registration:email.html.twig
    resetting:
        email:
            template: VanioUserBundle:Resetting:email.html.twig
    profile:
        form:
            type: FOS\UserBundle\Form\Type\ProfileFormType # or Vanio\UserBundle\Form\EmailOnlyProfileType when %vanio_user.email_only%
    service:
        mailer: fos_user.mailer.twig_swift

hwi_oauth:
    firewall_names: [%vanio_user.firewall_name%]