Skip to content

Instantly share code, notes, and snippets.

@stof
Created September 4, 2011 14:54
Show Gist options
  • Save stof/1192957 to your computer and use it in GitHub Desktop.
Save stof/1192957 to your computer and use it in GitHub Desktop.
Logging in by email or username with FOSUserBundle
fos_user:
# ...
service:
user_manager: my_user_manager
services:
my_user_manager:
class: Acme\UserBundle\Model\UserManager
parent: fos_user.user_manager.default
public: false
<?php
namespace Acme\UserBundle\Model;
use FOS\UserBundle\Entity\UserManager as BaseUserManager;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
class UserManager extends BaseUserManager
{
public function loadUserByUsername($username)
{
$user = $this->findUserByUsernameOrEmail($username);
if (!$user) {
throw new UsernameNotFoundException(sprintf('No user with name "%s" was found.', $username));
}
return $user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment