【问题标题】:No encoder has been configured for account with fosUserBundle symfony2.1没有为 fosUserBundle symfony2.1 帐户配置编码器
【发布时间】:2012-11-16 03:16:16
【问题描述】:

提交连接表单时出现此错误(我使用 FOSUserBundle 最新版本):

No encoder has been configured for account "MyApp\UtilisateurBundle\Entity\Utilisateur

这是我的实体:

    <?php
namespace MyApp\UtilisateurBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
 * @ORM\Entity
 */
class Utilisateur extends BaseUser
{
    /**
    * @ORM\Id
    * @ORM\Column(type="integer")
    * @ORM\generatedValue(strategy="AUTO")
    */
    protected $id;
    public function __construct()
    {
        parent::__construct();
    }

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

这是我的 app/config/security.yml :

imports:
- { resource: "@MyAppFilmothequeBundle/Resources/config/security.yml" }

这是我的 src/MyApp/FilmothequeBundle/Ressources/config/security.yml :

security:
providers:
    fos_userbundle:
        id: fos_user.user_manager

firewalls:
    main:
        pattern:      .*
        form_login:
            provider:       fos_userbundle
            login_path:     /myapp/login
            use_forward:    false
            check_path:     /myapp/login_check
            failure_path:   null
            default_target_path: /myapp
        logout:
            path:   /myapp/logout
            target: /myapp
        anonymous:    true

我按照本教程进行操作:http://j-place.developpez.com/tutoriels/php/ameliorez-vos-applications-developpees-avec-symfony2/#LVI-B-1

我怎样才能做到这一点? 提前谢谢你

【问题讨论】:

    标签: submit symfony-2.1 fosuserbundle encoder


    【解决方案1】:

    尝试将此添加到 security.yml 中的安全密钥中

    encoders:
            FOS\UserBundle\Model\UserInterface: sha512
    

    原来如此

    security:
        encoders:
            FOS\UserBundle\Model\UserInterface: sha512
    
        providers:
            ...
    
        firewalls:
            ...
    

    【讨论】:

      【解决方案2】:

      我在LexikJWTAuthenticationBundle 收到此错误。

      这对我有帮助 (config/packages/security.yaml):

      security:
          encoders:
            App\Entity\User:
              algorithm: bcrypt
      

      【讨论】:

        【解决方案3】:

        您只需在 security.yml 中添加此代码

            encoders:
                # use your user class name here
                App\Entity\User:
                    # Use native password encoder
                    # This value auto-selects the best possible hashing algorithm
                    # (i.e. Sodium when available).
                    algorithm: auto
        

        我使用 symfony 4.4

        为我工作

        【讨论】:

          猜你喜欢
          • 2020-07-20
          • 2012-03-26
          • 1970-01-01
          • 2019-08-24
          • 1970-01-01
          • 1970-01-01
          • 2021-07-29
          • 2016-08-01
          • 2022-12-01
          相关资源
          最近更新 更多