FriendsOfSymfony / FOSUserBundle

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages.

Home Page:https://symfony.com/doc/master/bundles/FOSUserBundle/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RegistrationController::registerAction()

kefimaher opened this issue · comments

Bonjour,
svp j'ai un erreur au niveau de fonction registerAction() je veux encode mon mot de passe avec la algorithme bcrypt mais quand j ajout UserPasswordEncoderInterface $encoder dans mon fonction il afficher un erreur voila la code :

<?php
namespace SocieteBundle\Controller;
 
use SocieteBundle\Form\UserType;
use SocieteBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
 
 
class RegistrationController extends Controller
{
 
    public function registerAction(Request $request, UserPasswordEncoderInterface $encoder)
    {
 
        $user = new User();
        $form = $this->createForm(UserType::class, $user);
        $form->handleRequest($request);
        if ($form->isSubmitted()) {
            $password = $encoder->encodePassword($user, $user->getPlainPassword());
            /*$user->getPlainPassword()   */
 
            $user->setPassword( $password);
            $user->setIsActive(true);
            $user->addRole("ROLE_ADMIN");
            $entityManager = $this->getDoctrine()->getManager();
            $entityManager->persist($user);
            $entityManager->flush();
            $this->addFlash('success', 'Votre compte à bien été enregistré.');
            //return $this->redirectToRoute('login');
        }
        return $this->render('SocieteBundle:login:register.html.twig', ['form' => $form->createView(), 'mainNavRegistration' => true, 'title' => 'Inscription']);
    }
}

Controller "SocieteBundle\Controller\RegistrationController::registerAction()" requires that you provide a value for the "$encoder" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

This is not a bug related to FOSUserBundle. Injecting services as action arguments require tagging the service with the appropriate tag in Symfony (and I'm not sure the autoconfiguration does it automatically when extending the old Symfony\Bundle\FrameworkBundle\Controller\Controller)