0

我尝试将 FOSUserBundle 与 FpOpenIDBundle 集成,但是在进行身份验证时遇到了问题。我收到错误

不支持“Alef\UserBundle\Entity\User”的实例。

我的课看起来像这样

<?php

namespace Alef\UserBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use FOS\UserBundle\Entity\User as BaseUser;
use FOS\UserBundle\Model\GroupInterface;
use Doctrine\ORM\Mapping as ORM;


 /**
 * User Entity
 *
 * @ORM\Entity
 * @ORM\Table( name="alef_users" )
 * 
 * @author James Morris <james@jmoz.co.uk>
 * @package SecurityBundle
 */
class User extends BaseUser implements \FOS\UserBundle\Model\GroupableInterface
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToMany(targetEntity="Alef\UserBundle\Entity\Group")
     * @ORM\JoinTable(name="alef_user_groups",
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
     * )
     */
    protected $groups;

    /**
     * @var string
     *
     * @ORM\Column(name="firstname", type="string", length=255)
     */
    protected $firstname;

    /**
     * @var string
     *
     * @ORM\Column(name="lastname", type="string", length=255)
     */
    protected $lastname;

    /**
     * @var string
     *
     * @ORM\Column(name="facebookId", type="string", length=255)
     */
    protected $facebookId;

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

    public function serialize()
    {
        return serialize(array($this->facebookId, parent::serialize()));;
    }

    public function unserialize($data)
    {
        list($this->facebookId, $parentData) = unserialize($data);
        parent::unserialize($parentData);
    }

    /**
     * @return string
     */
    public function getFirstname()
    {
        return $this->firstname;
    }

    /**
     * @param string $firstname
     */
    public function setFirstname($firstname)
    {
        $this->firstname = $firstname;
    }

    /**
     * @return string
     */
    public function getLastname()
    {
        return $this->lastname;
    }

    /**
     * @param string $lastname
     */
    public function setLastname($lastname)
    {
        $this->lastname = $lastname;
    }

    /**
     * Get the full name of the user (first + last name)
     * @return string
     */
    public function getFullName()
    {
        return $this->getFirstName() . ' ' . $this->getLastname();
    }

    /**
     * @param string $facebookId
     * @return void
     */
    public function setFacebookId($facebookId)
    {
        $this->facebookId = $facebookId;
        $this->setUsername($facebookId);
        $this->salt = '';
    }

    /**
     * @return string
     */
    public function getFacebookId()
    {
        return $this->facebookId;
    }

    /**
     * @param Array
     */
    public function setFBData($fbdata)
    {
        if (isset($fbdata['id'])) {
            $this->setFacebookId($fbdata['id']);
            $this->addRole('ROLE_FACEBOOK');
        }
        if (isset($fbdata['first_name'])) {
            $this->setFirstname($fbdata['first_name']);
        }
        if (isset($fbdata['last_name'])) {
            $this->setLastname($fbdata['last_name']);
        }
        if (isset($fbdata['email'])) {
            $this->setEmail($fbdata['email']);
        }
    }

    public function __construct()
    {
        parent::__construct();
        $this->facebookId = 0;
    }

}

我知道这是继承问题,因为 FpOpenId 继承了原始的 symfony 安全用户类,但 FOSUSer 没有从它继承。有没有办法更新 FPOpenIDBundle 以实际使用它?

4

2 回答 2

0

我的配置如下:

use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface;

class User implements UserInterface, GroupableInterface
{
}

由于超自定义功能,我正在覆盖整个班级。

只需添加

class User extends BaseUser implements UserInterface, GroupableInterface

问候, 马克斯

于 2012-04-11T08:09:53.313 回答
0
use FOS\UserBundle\Model\GroupableInterface;
use FOS\UserBundle\Model\GroupInterface;

class User extends BaseUser
{
    public function addGroup(GroupInterface $group)
    {
        parent::addGroup($group);
    }
}
于 2012-04-28T10:45:34.717 回答