0

I'm trying since 3 hours to install and configure FOSuser, which many developpers adviced me to use it.I wanted actually to make a normal login form without to use FOS but I had a lot of problems.I followed all steps in the documentation. the installation was ok , the configuration also but everytime when I try to log in , it shows "Bad credentials".So i find somehow this command that I executed :php app/console fos:user:create i give name-email-password. it work somehow but only with what i write, I mean when I register user in my registration form and try to log in it shows "Bad credentials".I hope that I was clear else please tell me what do you need to know Here are my Users.php where i have all my users info to login...

namespace test\indexBundle\Document;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\Security\Core\User\UserInterface;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * 
 * @MongoDB\Document
 */

class Users extends BaseUser 
{


    /**
     * @MongoDB\Id
     */
    protected $id;

    /**
     * @MongoDB\String
     */
    protected $userId;

    /**
     * @MongoDB\String
     */
    protected $userEmail;

    /**
     * @MongoDB\String
     */
    protected $userPassword;


    /**
     * @MongoDB\String
     */
    protected $salt;


    /**
     * @MongoDB\Int
     */
    protected $isActive;


    public function __construct()
    {
        parent::__construct();
        $this->isActive = true;
        $this->salt = md5(uniqid(null, true));
    }


    /**
     * Set id
     *
     * @param id $id
     */
    public function setId($id)  
    {  
        $this->id = $id;  
    }  

    /**
     * Get id
     *
     * @return id $id
     */
    public function getId()  
    {  
        return $this->id;  
    } 


    /**
     * Set userId
     *
     * @param string $userId
     */
    public function setUserId()  
    {  
        $this->userId = $this->salt;  
    }  

    /**
     * Get userId
     *
     * @return string $userId
     */
    public function getUserId()  
    {  
        return $this->userId;  
    } 

    /**
     * Set userName
     *
     * @param string $userName
     */
    public function setUserName($userName)  
    {  
        $this->userName = $userName;  
    }  

    /**
     * Get userName
     *
     * @return string $userName
     */
    public function getUserName()  
    {  
        return $this->username;  
    } 


    /**
     * Set userEmail
     *
     * @param string $userEmail
     */
    public function setUserEmail($userEmail)  
    {  
        $this->userEmail = $userEmail;  
    }  

    /**
     * Get userEmail
     *
     * @return string $userEmail
     */
    public function getUserEmail()  
    {  
        return $this->userEmail;  
    } 


    /**
     * Set userPassword
     *
     * @param string $userPassword
     */
    public function setPassword($userPassword)  
    {  
        $this->userPassword = $userPassword;  
    }  

    /**
     * Get userPassword
     *
     * @return string $userPassword
     */
    public function getPassword()  
    {  
        return $this->userPassword;  
    } 

    /**
     * @inheritDoc
     */
    public function getSalt()
    {
        return '';
    }



    /**
     * @inheritDoc
     */
    public function getRoles()
    {
        return array('ROLE_USER');
    }

    /**
     * @inheritDoc
     */
    public function eraseCredentials()
    {
    }

    /**
     * @see \Serializable::serialize()
     */
    public function serialize()
    {
        return serialize(array(
            $this->id
        ));
    }

    /**
     * @see \Serializable::unserialize()
     */
    public function unserialize($serialized)
    {
        list (
            $this->id
        ) = unserialize($serialized);
    }
}

and here my security.yml:

jms_security_extra:
    secure_all_services: false
    expressions: true

security:
    encoders:

        FOS\UserBundle\Model\UserInterface: sha512
        test\indexBundle\Document\Users:
            algorithm:        sha1 
            encode_as_base64: false
            iterations:      1  


    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]


    providers:


        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            pattern:   ^/
            anonymous: true


            form_login:
                check_path: /login_check
                login_path: /login
                provider: fos_userbundle
                post_only: true
                use_forward: false
                username_parameter:             email
                password_parameter:             password
                failure_path:                   null
                failure_forward:                false
                target_path_parameter: redirect_url
            logout:
                path:   /logout
                target: /blog


    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

and login function:

public function loginAction()
    {

        $request = $this->getRequest();
        $session = $request->getSession();




        if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) 
        {
            return $this->redirect($this->generateUrl('index_homepage'));
        }



        if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) 
        {
            $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } 
        else 
        {
            $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
            $session->remove(SecurityContext::AUTHENTICATION_ERROR);
        }


        return $this->render('indexBundle:index:logIn.html.twig', array(
                'last_username' => $session->get(SecurityContext::LAST_USERNAME),
                'error'         => $error,
        ));
    }

1 Answer 1

0

I might be wrong but I think FOSUserBundle requires a user to be activated after it's been created if you use the form registration, it's send out and email with a link I believe. I think you can use app/console fos:user:activate to activate if there is no email.

Sign up to request clarification or add additional context in comments.

2 Comments

Actually I'm doing like this:I have a registration form that I made, this form send the data to my Users.php (my table in mongodb:Users) after I have to login with a form that I made also without FOSUser layout. so with this login form when I try to login from my Users table , it doesn't show nothing, I dont know where is my mistake?
I'm not sure what you mean but the asbtract User model sets enabled to false in the __construct so unless you are specifically enabling the user in your registration it won't be accessible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.