安全性: 编码器: 的appbundle \实体\ Usuario: 算法:bcrypt #https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded 供应商: db_provider: 实体: 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 }
答案 0 :(得分: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');
}
}