Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Problem redirect after login when using FOSUser Symfony4

$
0
0

http://blog.test/register and http://blog.test/login works well, so when I access from http://blog.test/admin I am redirected to http://blog.test/login and and when I log in i have this error : Access Denied. enter image description here And when I click on Logs I have:

enter image description here My config is :

<?php

// src/Entity/User.php

namespace App\Entity;

use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM;

/** * @ORM\Entity * @ORM\Table(name="fos_user") */ class User extends BaseUser { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id;

public function __construct()
{
    parent::__construct();
    // your own logic
}

}

config\packages\framework.yaml

framework:    
    templating:
        engines: ['twig', 'php']

config\packages\security.yaml

security:
encoders:
    FOS\UserBundle\Model\UserInterface: bcrypt

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
    in_memory: { memory: null }
    fos_userbundle:
        id: fos_user.user_provider.username_email
firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        pattern: ^/
        user_checker: security.user_checker
        form_login:
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager

        logout: true
        anonymous: true

        # activate different ways to authenticate
        # https://symfony.com/doc/current/security.html#firewalls-authentication

        # https://symfony.com/doc/current/security/impersonating_user.html
        # switch_user: true

# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, role: ROLE_ADMIN }

config\routes\fos_user.yaml

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

I searched everywhere and I had no solution, I even tried to remove the templating: engines: ['twig', 'php']

I have this error : enter image description here

I removed the twig and I put only PHP like that : engines: ['php'] [enter image description here]4

I can't found any solution. How can I resolve this problem. Thanks a lot


Viewing all articles
Browse latest Browse all 3925

Trending Articles