0

I try add provider.What I'm doing wrong.

I have entity class, and I would like to extend this class

namespace AppBundle\Service;

use AppBundle\Entity\Pracownik;
use Symfony\Component\Security\Core\User\UserInterface;


class Userek extends Pracownik implements UserInterface
{
    public function getUsername()
    {
        return $this->getLogin();
    }

    public function getSalt()
    {
        // you *may* need a real salt depending on your encoder
        // see section on salt below
        return null;
    }

    public function getPassword()
    {
        return $this->getLogin();
    }

    public function getRoles()
    {
        return array('ROLE_PRACOWNIK');
    }

    public function eraseCredentials()
    {
    }

    public function isSuperAdmin()
    {
        return false;
    }

}

in security.yml i add

encoders:
        AppBundle\Service\Userek: plaintext
providers:
    pracownik_db_provider:
        entity:
            class: AppBundle\Service\Userek
            property: login
firewalls:
     main:
          pattern: ^/
          form_login:
              provider: pracownik_db_provider
              login_path: /login
              check_path: /login_check
          logout:
              path: /logout
              target: /login

When I try login, i got message:

The class 'AppBundle\Service\Userek' was not found in the chain configured namespaces AppBundle\Entity, FOS\UserBundle\Model"

If I implements Class Pracownik adding methods from the implemented class without creating an additional new class extending the Pracownik class - works

pierzcha
  • 11
  • 3
  • User classs is not the same as user provider. https://symfony.com/doc/3.4/security/custom_provider.html – malcolm Jan 10 '18 at 06:50

1 Answers1

1

Try to move your Userek class to the AppBundle\Entity\ folder, because Doctrine expects to find model classes on that folder Entity\.

Just move AppBundle\Service\Userek.php to AppBundle\Entity\Userek.php and come back if you still get the error message.

If you want Doctrine use another folder to store your model classes or entities, you can find some help to do that here or on the full documentation Doctrine configurations.

Yulio Aleman Jimenez
  • 1,642
  • 3
  • 17
  • 33