Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7853165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:36:13+00:00 2026-06-02T19:36:13+00:00

I have a question about the FOSUserBundle for Symfony 2.0.x. In there documentation you

  • 0

I have a question about the FOSUserBundle for Symfony 2.0.x.
In there documentation you can find a way to change the login to work with either username and email. That works great! But I want to login to work with just the email. So I added a function in my CustomUserManager (extends from the original) that makes sure you just can logon with your email.

namespace Frontend\UserBundle\Model;

use FOS\UserBundle\Entity\UserManager;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;

class CustomUserManager extends UserManager
{
    public function loadUserByUsername($email)
    {
        /*$user = $this->findUserByUsernameOrEmail($username);

        if (!$user) {
            throw new UsernameNotFoundException(sprintf('No user with name "%s" was found.', $username));
        }

        return $user;*/

        //Change it to only email (Default calls loadUserByUsername -> we send it to our own loadUserByEmail)
        return $this->loadUserByEmail($email);
    }

    public function loadUserByEmail($email)
    {
        $user = $this->findUserByEmail($email);

        if (!$user) {
            throw new UsernameNotFoundException(sprintf('No user with email "%s" was found.', $email));
        }

        return $user;

    }
}

But now I have a problem that I need to control the values that are saved in the session. He saves my username in the session and when the system checks this there will be no email (Because he only checks on email) available.

So my question is how/where can you change the value that is stored inside the username variable.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:36:14+00:00Added an answer on June 2, 2026 at 7:36 pm

    This can be done by overriding setters in the User entity:

    <?php
    
    namespace Acme\UserBundle\Entity;
    
    use FOS\UserBundle\Entity\User as BaseUser;
    use Doctrine\ORM\Mapping as ORM;
    use Gedmo\Mapping\Annotation as Gedmo;
    
    /**
     * @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
     * @ORM\Table(name="users")
     */
    class User extends BaseUser
    {
    
        // ...
    
        // override methods for username and tie them with email field
    
        /**
         * Sets the email.
         *
         * @param string $email
         * @return User
         */
        public function setEmail($email)
        {
            $this->setUsername($email);
    
            return parent::setEmail($email);
        }
    
        /**
         * Set the canonical email.
         *
         * @param string $emailCanonical
         * @return User
         */
        public function setEmailCanonical($emailCanonical)
        {
            $this->setUsernameCanonical($emailCanonical);
    
            return parent::setEmailCanonical($emailCanonical);
        }
    
        // ...
    
    }
    

    It’s not clear from your question, but from your namespaces I assume that you have your own child bundle that uses FOSUserBundle as its parent bundle (as per FOSUserBundle documentation, example “b”).

    If you do, you can then easily override Forms and templates in order to remove any username fields from the UI and replace them with email fields. Since you have overridden the email setters as per above, username property will be populated properly.

    Although this works, it’s not a very nice solution. The downside is that you will still have username and usernameCanonical columns in the database. We originally wanted to remove these altogether, but this would require too many changes in FOSUserBundle (the username attribute is required by \FOS\UserBundle\Model\UserInterface, and bundle code depends on it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this question about umbraco structuring and I can't find the answer anywhere.
I have a question about: how can I use foreach the service's namespaces in
I have question about the beta Open Graph stuffs. The documentation I am looking
I have question about parsing a specific json string. I didn't find anything which
I have question about throw. How will the throw work in the following code?
Have a question about VBS: How can i start a new window (e.g. of
I'm learning asp.net. I have question about example buttons I can use two types
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.