class SecurityController extends AbstractController
{
#[Route(path: ”, name: ‘app_login’)]
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
#[Route(path: '/logout', name: 'app_logout')]
public function logout(): void
{
throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
#[Route(path: '/redirect', name: 'redirect')]
public function redirectAction(Security $security) {
if ($security->isGranted('ROLE_ADMIN')) { return $this->redirectToRoute('app_login');}
if ($security->isGranted('ROLE_STUDENT')) { return $this->redirectToRoute('app_student');}
if ($security->isGranted('ROLE_TEACHER')) { return $this->redirectToRoute('app_home_teacher'); }
return $this->redirectToRoute('app_login');
}
}
this workd but i feel i did it in a different way? is that true?
New contributor
MaliceEU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.