add user management
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Security\AccessDeniedPageRenderer;
|
||||
use App\Security\ApplicationRoles;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
@@ -11,13 +15,25 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
final class SecurityController extends AbstractController
|
||||
{
|
||||
#[Route('/admin/login', name: 'admin_login')]
|
||||
public function login(AuthenticationUtils $authUtils): Response
|
||||
{
|
||||
// Wenn bereits eingeloggt → direkt ins Dashboard
|
||||
if ($this->getUser() !== null && $this->isGranted('ROLE_ADMIN_AREA')) {
|
||||
public function login(
|
||||
Request $request,
|
||||
AuthenticationUtils $authUtils,
|
||||
AccessDeniedPageRenderer $accessDeniedPageRenderer,
|
||||
): Response {
|
||||
$user = $this->getUser();
|
||||
|
||||
if ($user !== null && $this->isGranted(ApplicationRoles::ROLE_ADMIN_AREA)) {
|
||||
return $this->redirectToRoute('admin_dashboard');
|
||||
}
|
||||
|
||||
if ($user !== null) {
|
||||
return $accessDeniedPageRenderer->renderForbidden(
|
||||
$request,
|
||||
'admin',
|
||||
ApplicationRoles::ROLE_ADMIN_AREA,
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('admin/security/login.html.twig', [
|
||||
'last_username' => $authUtils->getLastUsername(),
|
||||
'error' => $authUtils->getLastAuthenticationError(),
|
||||
@@ -27,7 +43,7 @@ final class SecurityController extends AbstractController
|
||||
#[Route('/admin/logout', name: 'admin_logout')]
|
||||
public function logout(): void
|
||||
{
|
||||
// Symfony interceptet diese Route, daher bleibt sie leer.
|
||||
// Symfony intercepts this route via the firewall logout configuration.
|
||||
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Chat;
|
||||
|
||||
use App\Security\AccessDeniedPageRenderer;
|
||||
use App\Security\ApplicationRoles;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
@@ -19,12 +22,25 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
final class SecurityController extends AbstractController
|
||||
{
|
||||
#[Route('/chat/login', name: 'chat_login', methods: ['GET', 'POST'])]
|
||||
public function login(AuthenticationUtils $authUtils): Response
|
||||
{
|
||||
if ($this->getUser() !== null && $this->isGranted('ROLE_CHAT_USER')) {
|
||||
public function login(
|
||||
Request $request,
|
||||
AuthenticationUtils $authUtils,
|
||||
AccessDeniedPageRenderer $accessDeniedPageRenderer,
|
||||
): Response {
|
||||
$user = $this->getUser();
|
||||
|
||||
if ($user !== null && $this->isGranted(ApplicationRoles::ROLE_CHAT_USER)) {
|
||||
return $this->redirectToRoute('chat_index');
|
||||
}
|
||||
|
||||
if ($user !== null) {
|
||||
return $accessDeniedPageRenderer->renderForbidden(
|
||||
$request,
|
||||
'chat',
|
||||
ApplicationRoles::ROLE_CHAT_USER,
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('chat/security/login.html.twig', [
|
||||
'last_username' => $authUtils->getLastUsername(),
|
||||
'error' => $authUtils->getLastAuthenticationError(),
|
||||
@@ -34,6 +50,7 @@ final class SecurityController extends AbstractController
|
||||
#[Route('/chat/logout', name: 'chat_logout', methods: ['GET'])]
|
||||
public function logout(): void
|
||||
{
|
||||
// Symfony intercepts this route via the firewall logout configuration.
|
||||
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user