Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace RedK\Core\IndexBundle\Entity;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Symfony\Component\Security\Core\User\UserProviderInterface;
- use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
- use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
- use Doctrine\ORM\EntityRepository;
- use Doctrine\ORM\NoResultException;
- class AccountsRepository extends EntityRepository implements UserProviderInterface
- {
- public function loadUserByUsername($username)
- {
- $q = $this
- ->createQueryBuilder('u')
- ->select('u, g')
- ->leftJoin('u.groups', 'g')
- ->where('u.email = :email')
- ->setParameter('email', $username)
- ->getQuery();
- try
- {
- $user = $q->getSingleResult();
- }
- catch (NoResultException $e)
- {
- throw new UsernameNotFoundException(
- sprintf('Unable to find an active account identified by "%s".', $username),
- null, 0, $e);
- }
- return $user;
- }
- public function refreshUser(UserInterface $user)
- {
- $class = get_class($user);
- if (!$this->supportsClass($class)) {
- throw new UnsupportedUserException(
- sprintf('Instances of "%s" are not supported.', $class));
- }
- return $this->loadUserByUsername($user->getUsername());
- }
- public function supportsClass($class)
- {
- return $this->getEntityName() === $class || is_subclass_of($class, $this->getEntityName());
- }
- }
Add Comment
Please, Sign In to add comment