[英]Login with pre-existing database in Symfony 3
I try to set up a form process in my newest Symfony application.我尝试在我最新的 Symfony 应用程序中设置表单流程。 I followed the Symfony's cookbook but with no success.
我遵循了 Symfony 的食谱,但没有成功。
I want to use a pre existing database where fields loginUtil and passUtil couple are my connection requirements.我想使用一个预先存在的数据库,其中字段 loginUtil 和 passUtil 是我的连接要求。
So I set my security.yml file like :所以我将我的 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
Set my entity who implements interface UserInterface according documentation根据文档设置我实现接口 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()
{
}
}
?>
My controller who only returns my form view :我的控制器只返回我的表单视图:
<?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');
}
}
My routing.yml我的路由.yml
homepage:
path: /
defaults: { _controller: CustomerCustomerBundle:Default:index }
login:
path: /login
defaults:
_controller: CustomerCustomerBundle:Default:login
login_check:
path: /login_check
logout:
path: /logout
And my authenticate form :我的身份验证表格:
{% 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 %}
I saw in /var/logs/dev.log
that my username is submited correctly and requestes with doctrine but not password, he is empty.我在
/var/logs/dev.log
看到我的用户名已正确提交并请求使用原则而不是密码,他是空的。 So logically my credentials are bad.所以从逻辑上讲,我的凭据很糟糕。
Anyone could put me on the way with what i'm doing wrong ?任何人都可以让我了解我做错了什么?
Finally I found a solution.最后我找到了解决方案。
I don't understand why for now.我暂时不明白为什么。 I needed to add somme params inside encoders section like that :
我需要在编码器部分中添加一些参数,如下所示:
encoders:
Customer\CustomerBundle\Entity\utilisateur:
algorithm: sha1
encode_as_base64: false
iterations: 1
I need to document myself now to understand why.我现在需要记录自己以了解原因。
Thx to you guys !!谢谢你们!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.