无法使用FOSUserBundle登录

时间:2014-07-15 08:36:20

标签: php symfony

我正在为管理面板编写身份验证系统,因此任何具有admin /前缀的链接都会受到保护,并且无需登录即可重新定向到登录表单。

问题是我无法登录,在输入信用证后我才会重新定向到登录表单。

我还覆盖username字段以改为使用login字段。

security.yml:

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
        pattern: ^/
        anonymous: ~
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }

config.yml:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Acme\AdminBundle\Entity\Users
    registration:
        confirmation: { enabled: false }

我更新了记录,将ROLE_ADMIN设置为roles字段值。没别的了。发生了什么事?

EDIT。极致\ AdminBundle \实体\用户:

<?php

namespace Acme\AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;

/**
 * Users
 */
class Users extends BaseUser
{
    /**
     * @var integer
     */
    protected $userId;

    /**
     * @var string
     */
    protected $fbid;

    /**
     * @var boolean
     */
    protected $emailConfirmed;

    /**
     * @var string
     */
    protected $login; // etc

FOS \ UserBundle \型号\用户:

abstract class User implements UserInterface, GroupableInterface
{
    /**
     * @var integer
     */
    protected $id;

    /**
     * @var string
     */
    protected $username;

    /**
     * @var string
     */
    protected $usernameCanonical;

    /**
     * @var string
     */
    protected $email;

    /**
     * @var string
     */
    protected $emailCanonical;

users.orm.xml:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Acme\AdminBundle\Entity\Users" table="users" repository-class="Acme\AdminBundle\Repository\UsersRepository">
    <attribute-overrides>
        <attribute-override name="username">
            <field name="login" type="string" column="login" length="128" nullable="false"/>
        </attribute-override>
    </attribute-overrides>
    <id name="userId" type="integer" column="user_id">
      <generator strategy="IDENTITY"/>
    </id>
    <field name="fbid" type="string" column="fbid" length="20" nullable="false"/>
    <field name="emailConfirmed" type="boolean" column="email_confirmed" nullable="false"/>

user.orm.xml(FOSUserBundle xml):

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                  http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <mapped-superclass name="FOS\UserBundle\Model\User">

        <field name="username" column="username" type="string" length="255" />

0 个答案:

没有答案