Deploying Symfony2 app getting fosuserbundle error

2019-01-15 18:20发布

I have installed my Symfony project on another computer with the same specifications, and I receive the following error when I login with fosuserbundle:

Authentication request could not be processed due to a system problem.

I can't find anything of interest in the app/logs files. I run the app in dev mode. Cleared cache both manually and from the console. I setup the db with doctrine:database:create. It works to create a new user with fos:user:create and it's successfully saved to the database.

I have no idea where to go from here.

10条回答
仙女界的扛把子
2楼-- · 2019-01-15 18:31

Check to make sure your database is up to date. This fixed my issue when I received this error.

php app/console doctrine:schema:update --dump-sql

edit: spelling

查看更多
爷的心禁止访问
3楼-- · 2019-01-15 18:42

In a deploy process usually it's an environment problem (assuming that the app works fine in a dev station). FOSUserBundle it's great but for some reason it doesn't show very well the problems behind it.

As the error message says: ".. could not be processed due to a system problem."

if cleaning the cache nor updating the schema works, I would recommend try to bypass FOSUserBundle (usually the issue is between your code/configuration and the server environment) and let your bundle with the default errorhandler and logger inform any problem.

in my case it was a driver problem. (install pdo)

to bypass it, the simplest way is to remove security to a controller_action in security.yml

access_control:
{ path: ^/SomeCRUD, role: IS_AUTHENTICATED_ANONYMOUSLY }

then, if you access it, it should be able to log the issue and you should be able to fix it.

hope it helps

查看更多
ゆ 、 Hurt°
4楼-- · 2019-01-15 18:42

Make sure that your User entity implements the UserInterface

<?php

namespace UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * BaseUser
 */
class BaseUser implements UserInterface
{
    /**
     * @var integer
     */
    protected $id;

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

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

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

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

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

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


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

    /**
     * Set name
     *
     * @param string $name
     * @return BaseUser
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set username
     *
     * @param string $username
     * @return BaseUser
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

    /**
     * Get username
     *
     * @return string 
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Set password
     *
     * @param string $password
     * @return BaseUser
     */
    public function setPassword($password)
    {
        if (!is_null($password)) {
            $this->password = $password;
        }

        return $this;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set email
     *
     * @param string $email
     * @return BaseUser
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set roles
     *
     * 
     * @return BaseUser
     */
    public function setRoles($roles)
    {
        $this->roles = $roles;
    }

    /**
     * Get roles
     */
    public function getRoles()
    {
        // Do what ever make sense to you here 
        return explode("|", $this->roles)
    }

    /**
     * Set isActive
     *
     * @param boolean $isActive
     * @return BaseUser
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;

        return $this;
    }

    /**
     * Get isActive
     *
     * @return boolean 
     */
    public function getIsActive()
    {
        return $this->isActive;
    }

    public function eraseCredentials()
    {
    }

    public function getSalt()
    {
        return null;
    }
}
查看更多
爷、活的狠高调
5楼-- · 2019-01-15 18:42

I had the same problem. I was able to build and populate the database with php app/console doctrine:schema:update --force; php app/console doctrine:fixtures:load; but the symfony app couldn't access the database.

The problem was I'd set database_host: 127.0.0.1 in parameters.yml but mysql was expecting me to connect through localhost. Updating parameters.yml fixed the problem. I'm still confused as to why the command line stuff worked...

查看更多
不美不萌又怎样
6楼-- · 2019-01-15 18:42

I was having the exact same issue. And the steps I took were the following:

  1. I cleared the cache
  2. I brought down all my db tables and recreated them again via my migrations
  3. I replaced where I had used single quotes(') with double quotes(") in my entity annotations for arguments to constraint methods

    Example

    //src/SomeBundle/Model/user.php
    <?php
    /**
    *
    * @Assert\File(
    *  maxSize='512k',
    *  mimeTypes={'image/png', 'image/jpeg', 'image/gif'},
    *  mimeTypesMessage= 'Please upload a valid png, gif or jpeg file below 512Kb'
    * )
    */
    private $profilePic;
    
    ?>
    

    This got replaced with

    <?php
    /**
    *
    * @Assert\File(
    *  maxSize="512k",
    *  mimeTypes={"image/png", "image/jpeg", "image/gif"},
    *  mimeTypesMessage= "Please upload a valid png, gif or jpeg file below 512Kb"
    * )
    */
    private $profilePic;
    ?>
    

After doing this, I tried the authentication again and it worked!

查看更多
SAY GOODBYE
7楼-- · 2019-01-15 18:43

You might have set a wrong password in your parameters.yml because of which it might not be able to connect to the DB. The above mentioned error occurs when the app is not able to connect to DB to check if the user is authentic. (I also faced the same error and this was my problem, hope it helps)

查看更多
登录 后发表回答