2013-08-25 59 views
0

我是FOSUserBundle的新手,並且在幾個小時內,我正在努力解決這個錯誤......並且無法在網站中找到合適的答案。symfony2 FOSUserBundle登錄返回'錯誤的憑據'

誰能幫助我PLZ: - *

這是我的孩子用戶實體

<?php 
// src/Blogger/BlogBundle/Entity/CommonUser.php 

namespace Blogger\BlogBundle\Entity; 

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


/** 
* @ORM\Entity(repositoryClass="Blogger\BlogBundle\Entity\Repository\CommonUserRepository") 
* @ORM\Table(name="CommonUser") 
* @ORM\HasLifecycleCallbacks 
*/ 
class CommonUser extends BaseUser 
{ 

    /** 
    * @ORM\OneToMany(targetEntity="Request", mappedBy="commonUser") 
    */ 
    protected $requests; 



    public function __construct() 
    { 
     parent::__construct(); 

     $this->requests = new ArrayCollection(); 


    } 



    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer", nullable=false) 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 


... 
... 
... 

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


    public function getSalt() 
    { 
     return ''; 
    } 
... 

} 

而且這是request.php類

<?php 
// src/Blogger/BlogBundle/Entity/Request.php 

namespace Blogger\BlogBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Doctrine\Common\Collections\ArrayCollection; 
use Blogger\BlogBundle\Entity\Repository\RequestRepository; 
/** 
* @ORM\Entity(repositoryClass="Blogger\BlogBundle\Entity\Repository\requestRepository") 
* @ORM\Table(name="request") 
* @ORM\HasLifecycleCallbacks 
*/ 
class Request 
{ 

    /** 
    * @ORM\OneToMany(targetEntity="Note", mappedBy="request") 
    */ 
    protected $notes; 

    public function __construct() 
    { 
     $this->notes = new ArrayCollection(); 


     $this->setCreated(new \DateTime()); 
     $this->setUpdated(new \DateTime()); 
    } 

    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\ManyToOne(targetEntity="CommonUser", inversedBy="requests") 
    * @ORM\JoinColumn(name="user_id", referencedColumnName="id") 
    */ 
    protected $commonUser; 

    /** 
    * @ORM\Column(type="text") 
    */ 
    protected $request; 

    .... 
    .... 
    .... 



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

    .... 
    .... 
    .... 
} 

,這是我的安全文件

# app/config/security.yml 
security: 
    encoders: 
     FOS\UserBundle\Model\UserInterface: sha512 

    role_hierarchy: 
     ROLE_ADMIN:  ROLE_USER 
     ROLE_SUPER_ADMIN: ROLE_ADMIN 

    providers: 
     fos_userbundle: 
      id: fos_user.user_provider.username 

    firewalls: 
     main: 
      pattern: ^/ 
      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: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/admin/, role: ROLE_ADMIN } 
+0

爲什麼CommomUser :: getSalt返回''?在security:下添加hide_user_not_found:false。這至少會告訴你用戶正在被加載。 – Cerad

回答

1

當您使用FOSUserBundle提供的控制器註冊時,存儲在數據庫中的密碼將使用500次SHA1和隨機生成的鹽進行加密。所以如果你總是通過函數getSalt()返回「」,密碼永遠不會匹配。 請勿覆蓋此功能。

但是您可以覆蓋FOSUserBundle中的控制器,更多關於offical documentation中的控制器。

public function getSalt() 
{ 
    return ''; 
} 
1

試着更新密碼。 在終端輸入:

php fos:user:change-password $username $password

其中$user是用戶名和$password新密碼。

相關問題