Что это за ошибка, которую я получаю, когда пытаюсь хешировать свой пароль в symfony 4 - PullRequest
0 голосов
/ 08 января 2019

Это ошибка

Аргумент 1 передан Symfony \ Component \ Security \ Основные \ кодировщика \ UserPasswordEncoder :: encodePassword () должен быть примером Symfony \ Component \ Security \ Core \ User \ UserInterface, экземпляр App \ Entity \ User задано, вызвано C: \ Users \ willi \ Desktop \ Crowdin \ src \ Controller \ CompteController.php в линия 44

CompteController.php:

  /** 
 * @Route("/inscriptions", name="inscription")
 */
public function inscriptions(Request $request, ObjectManager $manager, UserPasswordEncoderInterface $encoder) {
    $user = new User();

    $form = $this->createForm(RegistrationType::class, $user);

    $form->handleRequest($request);

    if($form->isSubmitted() && $form->isValid()) {

        $hash = $encoder->encodePassword($user, $user->getPassword());

        $user->setPassword($hash);

        $manager->persist($user);
        $manager->flush();

        return $this->redirectToRoute('login');
    }

    return $this->render('compte/inscriptions.html.twig', [
        'form' => $form->createView()
    ]);
}

User.php:

<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
 * @UniqueEntity(
 *  fields={"email"},
 *  message="L'email que vous avez indiqué est déja utilisé !"
 * )
 */
class User implements UserInterface
{

1 Ответ

0 голосов
/ 09 января 2019

Похоже, вы только импортируете интерфейс в локальное пространство имен, но фактически не реализуете его.

namespace foo;         // namespace declaration
use Bar\UserInterface; // namespace import, does not actually implement it.

class User implements UserInterface { // <- this is the important part
  // now you need to implement the methods specified in the interface.
}

В качестве альтернативы, предположим, что класс Bar\User реализует Bar\UserInterface:

class User extends Bar\User {
  // now you only need to define/redefine the specific things that you want to
}
...