Answer the question
In order to leave comments, you need to log in
What is the error when implementing authentication through login and email on Symfony3?
Learning symfony3
Trying to implement symfony.com/doc/current/security/entity_provider.h...
But when I try to login to the application I get - The Doctrine repository "Doctrine\ORM\EntityRepository" must implement Symfony\Bridge\Doctrine\Security\User\ UserLoaderInterface.
<?php
//zenaku/AppBundle/Entity/Repository/UsersRepository.php
namespace zenaku\AppBundle\Entity\Repository;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping AS ORM;
class UsersRepository extends EntityRepository implements UserLoaderInterface
{
public function loadUserByUsername($username)
{
return $this->createQueryBuilder('u')
->where('u.username = :username OR u.email = :email')
->setParameter('username', $username)
->setParameter('email', $username)
->getQuery()
->getOneOrNullResult();
}
}
<?php
//zenaku/AppBundle/Entity/Users.php
namespace zenaku\AppBundle\Entity;
use Doctrine\ORM\Mapping AS ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
/**
* Users
*
* @ORM\Entity(repositoryClass="zenaku\AppBundle\Entity\Repository\UsersRepository")
* @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="username_UNIQUE", columns={"username"}), @ORM\UniqueConstraint(name="id_UNIQUE", columns={"id"}), @ORM\UniqueConstraint(name="email_UNIQUE", columns={"email"})}, indexes={@ORM\Index(name="fk_users_privileges_idx", columns={"privileges"})})
* @ORM\Entity
*/
class Users implements UserInterface, AdvancedUserInterface, \Serializable
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=16, nullable=false)
*/
private $username;
//...
}
security:
encoders:
zenaku\AppBundle\Entity\Users:
algorithm: bcrypt
encode_as_base64: true
cost: 15
providers:
db_hal:
entity:
class: zenakuAppBundle:Users
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
login_path: login
check_path: check_login
username_parameter: username
password_parameter: password
provider: db_hal
logout: ~
anonymous: ~
switch_user: { role: ROLE_UBERADMIN, parameter: _i_other_user}
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_UBERADMIN: ROLE_ADMIN
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY}
- { path: ^/admin, roles: ROLE_ADMIN}
- { path: ^/, roles: ROLE_USER}
Answer the question
In order to leave comments, you need to log in
Your annotation is overwritten in the entity (2 times the Entity annotation. The first with a turnip, the second time is empty)
It looks like the repository for your Users entity is not zenaku\AppBundle\Entity\Repository\UsersRepository
, but Doctrine\ORM\EntityRepository
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question