recranet/user-bundle

此包已被 废弃 并不再维护。未建议替代包。

Symfony2 的用户管理。兼容 Doctrine ORM

安装: 550

依赖者: 0

建议者: 0

安全: 0

类型:symfony-bundle

1.1 2016-10-04 11:56 UTC

This package is auto-updated.

Last update: 2018-07-21 14:57:22 UTC


README

Symfony2 和 Doctrine 的用户管理

安装

使用 composer 安装包

"recranet/user-bundle": "^1.0"

在 AppKernel 中注册束

new Recranet\UserBundle\RecranetUserBundle(),

从束扩展 User 实体

<?php

namespace Acme\DemoBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

use Recranet\UserBundle\Entity\User as BaseUser;

/**
 * @ORM\Table(name="users")
 * @ORM\Entity()
 */
class User extends BaseUser
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
}

更新 config.yml

# Recranet User Bundle
recranet_user:
    user_class: Acme\DemoBundle\Entity\User
    firewall_name: main
    mailer:
        from_email: info@recranet.com
        from_name: Recranet
    registration: # Optional
        approval: false
        enabled: true

更新 security.yml

security:
    encoders:
        Acme\DemoBundle\Entity\User:
            algorithm: bcrypt
            cost: 16

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        doctrine:
            id: recranet_user.user_provider

    firewalls:            
        main:
            pattern:    ^/
            anonymous:  ~
            context: application
            form_login:
                login_path:  login
                check_path:  login_check

            logout:
                path:   logout
                target: /

    access_control:
        - { path: ^/%locale%/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/%locale%/password/reset, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/%locale%/password/request, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/%locale%/password/change, role: IS_AUTHENTICATED_FULLY }

更新 routing.yml

recranet_user:
    resource: "@RecranetUserBundle/Resources/config/routing.yml"
    prefix:   /