Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 4在新开发项目中,简单身份验证失败,错误为;由于系统问题,无法处理身份验证请求;_Php_Symfony_Authentication_Symfony4 - Fatal编程技术网

Php Symfony 4在新开发项目中,简单身份验证失败,错误为;由于系统问题,无法处理身份验证请求;

Php Symfony 4在新开发项目中,简单身份验证失败,错误为;由于系统问题,无法处理身份验证请求;,php,symfony,authentication,symfony4,Php,Symfony,Authentication,Symfony4,从symfony 4开始,当我尝试登录时,页面返回以下错误: “由于系统问题,无法处理身份验证请求” 在我的var/log/dev.log中,详细错误是: [2018-09-02 23:18:23] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException(co

从symfony 4开始,当我尝试登录时,页面返回以下错误:

“由于系统问题,无法处理身份验证请求”

在我的var/log/dev.log中,详细错误是:

[2018-09-02 23:18:23] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException(code: 0): Class 'App\\Entity\\User' does not exist at /home/www/xxx/yyy/symfoproject/vendor/symfony/security/Core/Authentication/Provider/DaoAuthenticationProvider.php:85, Doctrine\\Common\\Persistence\\Mapping\\MappingException(code: 0): Class 'App/Entity/User' does not exist at /home/www/xxx/yyy/symfoproject/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:93)"} []
我不理解,因为类App/Entity/User存在,我使用它生成带有./bin/console的数据库架构

my security.yaml代码:(在symfoproject/config/packages/security.yaml中)

我的用户实体代码(在symfoproject/src/entity/UserEntity.php中)


UserEntity.php
重命名为
User.php
,这样它就可以自动加载了。嘿,非常感谢!这就是这个错误:D
security:
    # https://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
    encoders:
        App\Entity\User:
            algorithm: bcrypt
    providers:
        my_db_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        #dev:
        #    pattern: ^/(_(profiler|wdt)|css|images|js)/
        #    security: false
        main:
            provider: my_db_provider
            anonymous: ~
            form_login:
                login_path: home
                check_path: home
            logout:
                path: /logout
                target: /

            # activate different ways to authenticate

            # http_basic: ~
            # https://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate

            # form_login: ~
            # https://symfony.com/doc/current/cookbook/security/form_login_setup.html
    role_hierarchy:
        ROLE_SUPER_ADMIN: [ROLE_USER]
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
 */
class User implements \Serializable, UserInterface
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=100, unique=true)
     */
    private $email;

    /**
     * @ORM\Column(type="string", length=64, nullable=true)
     */
    private $token_activation;

    /**
     * @var bool
     * @ORM\Column(name="is_active", type="boolean")
     */
    private $isActive;

    /**
     * @ORM\Column(type="string", length=64)
     */
    private $password;

    /**
     * @Assert\NotBlank()
     * @Assert\Length(max=4096)
     */
    private $plainPassword;

    /**
     * @var array
     * @ORM\Column(name="roles", type="array")
     */
    protected $roles;

    /**
     * @var int
     * @ORM\Column(type="smallint", options={"default":0})
     */
    private $initial_roll;

    public function __construct(string $email, array $roles = array(), bool $isActive = FALSE, string $password = "coucou", int $initial_roll = 0) {
        $this->email =$email;
        $brypt = new BCryptPasswordEncoder(4);
        $this->password = $brypt->encodePassword($password, $this->getSalt());
        $this->roles = $roles;
        $this->isActive = $isActive;
        $this->initial_roll = $initial_roll;
    }

    public function serialize() {
        return serialize(array(
            $this->id,
            $this->email,
            $this->password,
        ));
    }

    public function unserialize($serialized) {
        list (
            $this->id,
            $this->email,
            $this->password,
            ) = unserialize($serialized);
    }

    public function getRoles() {
        return $this->roles;
    }

    public function getPassword() {
        return $this->password;
    }

    public function getSalt() {
        return NULL;
    }

    public function getUsername() {
        return $this->email;
    }

    public function eraseCredentials() {
        $this->plainPassword = NULL;
    }

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

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

    /**
     * @param mixed $email
     */
    public function setEmail($email): void {
        $this->email = $email;
    }

    /**
     * @return mixed
     */
    public function getTokenActivation() {
        return $this->token_activation;
    }

    /**
     * @param mixed $token_activation
     */
    public function setTokenActivation($token_activation): void {
        $this->token_activation = $token_activation;
    }

    /**
     * @return bool
     */
    public function isActive(): bool {
        return $this->isActive;
    }

    /**
     * @param bool $isActive
     */
    public function setIsActive(bool $isActive): void {
        $this->isActive = $isActive;
    }

    /**
     * @return mixed
     */
    public function getPlainPassword() {
        return $this->plainPassword;
    }

    /**
     * @param mixed $plainPassword
     */
    public function setPlainPassword($plainPassword): void {
        $this->plainPassword = $plainPassword;
    }

    public function toArray() {
        return array(
            "id"=>$this->getId(),
            "mail"=>$this->getEmail(),
            "role(s)" => $this->getRoles(),
            "actif?" => $this->isActive(),
        );
    }

    /**
     * @return int
     */
    public function getInitialRoll(): int {
        return $this->initial_roll;
    }

    /**
     * @param int $initial_roll
     */
    public function setInitialRoll(int $initial_roll): void {
        $this->initial_roll = $initial_roll;
    }
}