0

To get started with security, check out the documentation:

https://symfony.com/doc/current/security.html

security: encoders: AppBundle\Entity\Usuario: algorithm: bcrypt # https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded providers: db_provider: entity: class: AppBundle:Usuario

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

    main:
        anonymous: ~
        form_login:
              login_path: login
              check_path: login
              default_target_path: admin

        logout:
            path: logout
            target: index

        remember_me:
                    secret:   '%secret%'
                    lifetime: 604800 # 1 week in seconds
                    path:     /
access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONIMOUSLY }
    - { path: ^/admin, roles: IS_AUTHENTICATED_FULLY }
Vitor
  • 1
  • 1
  • What do you have on /admin route? Maybe you got a circular redirect back to login page. – Srdjan Jan 31 '18 at 14:08
  • When I try to login the URL change to mydomain/login and it appear the message in the Browser "The page isn’t redirecting properly". – Vitor Jan 31 '18 at 14:25
  • Try changing default_target_path – Srdjan Jan 31 '18 at 14:26
  • Ok, after admin route you redirect to 'principal' or 'index', what happening there? Some of those controllers probably returning back to 'login' route. – Srdjan Jan 31 '18 at 14:58
  • @Srdjan I appreciate your help, and It make me go throught another way so I found that the name of my user database was wrong so because of this i was getting this error. I am new using symfony, and my mistake. Thanks a lot for your help. – Vitor Jan 31 '18 at 15:55

1 Answers1

0
/**
 * @Route("/login", name="login")
 */
public function loginAction(AuthenticationUtils $authUtils)
{

    // get the login error if there is one
$error = $authUtils->getLastAuthenticationError();

// last username entered by the user
$lastUsername = $authUtils->getLastUsername();

    $msg = '';

    if ($error != null) {
        $msg = 'Login ou Senha Inválidos!';
    }

    return $this->render($this->urlPage.'index.html.twig', array(
        'errorMsg' => $msg,
    ));


}

/**
 * @Route("/admin", name="admin")
 */
public function adminAction(AuthorizationCheckerInterface $authChecker)
{

    $authChecker = $this->get('security.authorization_checker');

    if ($authChecker->isGranted('ROLE_USUARIO')) {
        return $this->redirectToRoute('principal');
    } else if ($authChecker->isGranted('ROLE_CLIENTE')){
        return $this->redirectToRoute('principal');
    } else {
        return $this->redirectToRoute('index');
    }

}
Vitor
  • 1
  • 1
  • 1
    Is this an answer or an update to the question? It is best to edit the question itself when providing more information. – Cerad Jan 31 '18 at 15:04