<?php

namespace Listabierta\Bundle\MunicipalesBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * VoterRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class VoterRepository extends EntityRepository
{
}

<?php

namespace Listabierta\Bundle\MunicipalesBundle\Entity;

use Doctrine\ORM\EntityRepository;
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\NoResultException;

/**
 * VoterRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class VoterRepository extends EntityRepository
{
	public function loadUserByUsername($username)
	{
		$q = $this
		->createQueryBuilder('u')
		->where('u.username = :username')
		->setParameter('username', $username)
		->getQuery();
	
		try
		{
			// The Query::getSingleResult() method throws an exception
			// if there is no record matching the criteria.
			$user = $q->getSingleResult();
		}
		catch (NoResultException $e)
		{
			$message = sprintf(
					'Unable to find an active voter MunicipalesBundle:Voter object identified by "%s".',
					$username
			);
			throw new UsernameNotFoundException($message, 0, $e);
		}
	
		return $user;
	}
	
	/**
	 * {@inheritdoc}
	 */
	protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
	{
		$currentUser = $token->getUser();
	
		if ($currentUser instanceof UserInterface) {
			if ($currentUser->getPassword() !== $user->getPassword()) {
				throw new BadCredentialsException('The credentials were changed from another session.');
			}
		} else {
			if (!$presentedPassword = $token->getCredentials()) {
				throw new BadCredentialsException('The presented password cannot be empty.');
			}
	
			if (! $this->service->authenticate($token->getUser(), $presentedPassword)) {
				throw new BadCredentialsException('The presented password is invalid.');
			}
		}
	}
	
	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->find($user->getId());
	}
	
	public function supportsClass($class)
	{
		return $this->getEntityName() === $class
		|| is_subclass_of($class, $this->getEntityName());
	}
}

Add voters repository methods for login
Add voters repository methods for login
