Hello devs when I try to connect with my login form ( when I submit the form ) it doesn't work and gives me the following error:
Notice: A non well formed numeric value encountered
so thank you in advance for your answers
so I use the symfony 4 security component for authentication.
Here's the code:
Controller:
<?php
namespace App\Controller ;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\User ;
//Class pour authentification
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils ;
class SecurityController extends AbstractController
{
/**
* @Route("/login" , name="login")
*/
public function login(AuthenticationUtils $authentication)
{
$error = $authentication -> getLastAuthenticationError();
$lastUsername = $authentication -> getLastUsername();
return $this -> render('Authentification/login.html.twig' ,[
'error' => $error,
'last_username' => $lastUsername,
]) ;
}
}
Security.yaml :
security:
encoders:
App\Entity\User:
algorithm: bcrypt
cost : 14
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: lazy
form_login:
remember_me: false
check_path: /login
logout :
path: /logout
target: /
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
and the login page :
{% extends 'baseConnection.html.twig' %}
{% block title %}Se Connecter{% endblock %}
{% block body %}
<div class="container">
<br><br>
<h3>Page de Connection de l'application CUMA le PROGRES</h3>
<br><br>
<p class="btn float-right color-br" onclick="window.history.back();">Retour</p>
<br><br>
{% if error %}
<div class="alert alert-danger">
{% if error %}
{{ error.messageKey | trans(error.messagedata , 'security') }}
{% endif %}
</div>
{% endif %}
<form action="{{ path('login')}}" method="post">
<div class="form-group">
<label for="username">Nom d'utilisateur</label>
<input type="text" id="username" name="_username" class="form-control" placeholder="Vôtre nom d'utilisateur est du style: Prénom.Nom" value="{{ last_username }}">
</div>
<br>
<div class="form-group">
<label for="password">Mot de passe</label>
<input type="password" id="password" name="_password" class="form-control" placeholder="Vôtre mot de passe ..... ( en cas d'oublie aller voir Fabien ABISUR )">
</div>
<br><br>
<button type="submit" class="btn color-br">Se Connecter</button>
</form>
</div>
{% endblock %}
thank you in advance for your help (^_^)