0

我尝试在我最新的 Symfony 应用程序中设置表单流程。我按照 Symfony 的食谱进行操作,但没有成功。

我想使用一个预先存在的数据库,其中 loginUtil 和 passUtil 字段是我的连接要求。

所以我将我的 security.yml 文件设置为:

security:
    providers:
        main:
            entity: Customer\CustomerBundle\Entity\utilisateur
            property: loginUtil
    encoders:
        Customer\CustomerBundle\Entity\utilisateur:
        algorithm: sha1

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            pattern: ^/
            anonymous: true
            provider: main
            form_login:
                login_path: /login
                check_path: /login_check
            logout:
                path: /logout
                target: home_page

根据文档设置实现接口 UserInterface 的我的实体

<?php
namespace Customer\CustomerdBundle\Entity;

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

/**
 * utilisateur
 *
 * @ORM\Table(name="utilisateur")
 * @ORM\Entity(repositoryClass="Customer\CustomerdBundle\Repository\utilisateurRepository")
 */

class utilisateur implements UserInterface
{
    private $username;
    private $password;
    private $salt;
    private $roles;

    // declaration of other fields from pre existing database

    // setters and getters
    // ...
    //

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

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

    public function getsalt()
    {
        return $this->salt;
    }

    public function getusername()
    {
        return $this->username = $this->getLoginUtil();
    }

    public function eraseCredentials()
    {
    }
}
?>

我的控制器只返回我的表单视图:

<?php

namespace Customer\CustomerdBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->render('CustomerCustomerBundle:Default:tableLum.html.twig');
    }

    public function loginAction()
    {
        return $this->render('CustomerCustomerBundle:Default:formLogin.html.twig');
    }
}

我的路由.yml

homepage:
    path:     /
    defaults: { _controller: CustomerCustomerBundle:Default:index }

login:
    path: /login
    defaults:
    _controller: CustomerCustomerBundle:Default:login

login_check:
    path: /login_check

logout:
    path: /logout

我的身份验证表格:

{% extends "CustomerCustomerBundle::layout.html.twig" %}

{% block maincontentFormLogin %}
    <form action="{{ path('login_check') }}" method="post">
        <label for="username">Login :</label>
        <input type="text" id="username" name="_username" value="" />
        <br />
        <label for="password">Mot de passe :</label>
        <input type="password" id="password" name="_password" />
        <br />
        <input type="submit" value="Connexion" />
    </form>
{% endblock %}

我看到/var/logs/dev.log我的用户名提交正确,并且使用原则而不是密码请求,他是空的。所以从逻辑上讲,我的凭据很糟糕。

任何人都可以让我走上我做错的道路吗?

4

1 回答 1

0

最后我找到了解决方案。

我现在不明白为什么。我需要像这样在编码器部分添加一些参数:

encoders:
    Customer\CustomerBundle\Entity\utilisateur:
        algorithm: sha1
        encode_as_base64: false
        iterations: 1

我现在需要记录自己以了解原因。

谢谢你们!

于 2018-06-08T13:17:34.090 回答