-2

I'm trying to build some login functionality in Symfony. I'm a beginner with Symfony and I can't found a solution to my problem.

I'm using users from a mySQL database. When I log in with wrong credentials it prints an error on the login page, that I'm using wrong credentials. That's awesome, because that is what I want. But when I login with the correct credentials it goes to a blank page at /login_check. This is the tutorial I tried to follow: http://symfony.com/doc/current/cookbook/security/entity_provider.html

My Symfony version is 2.8.

Here is my security.yml

encoders:
    Trekkerslep\DashboardBundle\Entity\User:
        algorithm: bcrypt

providers:
    database_provider:
        entity:
            class: TrekkerslepDashboardBundle:User

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    default:
        anonymous: ~
        pattern: ^/
        form_login:
            provider: database_provider
            login_path: /login
            check_path: /login_check
            csrf_token_generator: security.csrf.token_manager
            default_target_path: trekkerslep_dashboard_main
            always_use_default_target_path: true

access_control:
     - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/, roles: [ROLE_USER] }

My User Entity looks like this:

class User implements UserInterface, \Serializable {

    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=50, unique=true)
     */
    protected $username;

    /**
     * @ORM\Column(type="string", length=64)
     */
    protected $password;

    /**
     * @ORM\Column(type="string", length=100, unique=true)
     */
    protected $email;

    /**
     * @ORM\Column(type="string")
     */
    protected $screenname;

    /**
     * @ORM\Column(type="datetime")
     */
    protected $created;

    /**
     * @ORM\Column(name="is_active", type="boolean")
     */
    protected $isActive;

    public function __construct() {
        $this->isActive = true;
    }

    public function getUsername() {
        return $this->getUsername();
    }

    public function getSalt() {
        return null;
    }

    public function getPassword() {
        return $this->password;
    }

    public function getRoles()
    {
        return array('ROLE_USER');
    }

    public function eraseCredentials() {

    }

    /** @see \Serializable::serialize() */
    public function serialize() {
        return serialize(array(
            $this->id,
            $this->username,
            $this->password,
            // see section on salt below
            // $this->salt,
        ));
    }

    /** @see \Serializable::unserialize() */
    public function unserialize($serialized) {
        list (
            $this->id,
            $this->username,
            $this->password,
            // see section on salt below
            // $this->salt
            ) = unserialize($serialized);
    }

And my routing.yml:

trekkerslep_dashboard_main:
    path:     /
    defaults: { _controller: TrekkerslepDashboardBundle:Dashboard:index }

trekkerslep_dashboard_login:
    path:     /login
    defaults: { _controller: TrekkerslepDashboardBundle:Security:login }

trekkerslep_dashboard_login_check:
    path:     /login_check

I hope somebody can help and sees what I'm doing wrong. Thanks in advance.

Jan Doornbos
  • 639
  • 6
  • 25
  • 1
    Possible duplicate of [Reference - What does this error mean in PHP? – Nothing is seen. The page is empty and white.](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – CBroe Jan 29 '16 at 15:37

1 Answers1

-1

First of all, if you can i highly suggest that you use FOSUserBundle. Even though it's a bundle that restrain you, it does work if you need something simple. Back to the subject. Here you have a route (trekkerslep_dashboard_login_check) that redirects to http://whateveryoururlis.dev/login_check . Since you do not use anything to manage the login yourself, i think you need to add a controller and a function in it so your login_check point to something that suits your needs. For example, you could redirect to a page that says "You managed to connect". By the way, if you're using the app_dev.php, you should see if you're logged in, or not.

Sometimes the symfony cache does try to beat you into submission. If your code is supposed to work but doesn't, you could try clearing it, sometimes it shows error you have that Symfony forgot to tell you.

Good luck!

LamaDelRay
  • 199
  • 2
  • 11
  • I don't think you did anything wrong previously, but i think the tutorial you followed was a bit flawed somewhere, and since you're beginning Symfony you couldn't see where. (And as a mater of fact me neither.) Have fun with fosuserbundle! – LamaDelRay Feb 01 '16 at 08:44