diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index d2bf263..0a72108 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -32,7 +32,7 @@ class UserController extends AbstractController ]); } - #[Route('/{id}', name: 'view')] + #[Route('/{id}', name: 'view', methods: ['GET'])] public function userProfile(Request $request, EntityManagerInterface $entityManager): Response { if ($this->isGranted('ROLE_SUDALYS_ADMIN')) { @@ -42,10 +42,30 @@ class UserController extends AbstractController throw $this->createNotFoundException('User not found'); } $userOrganizations = $this->userOrganizationService->getUserOrganizations($user); + return $this->render('user/profile.html.twig', [ + 'user' => $user, + 'userOrganizations' => $userOrganizations, + ]); } - return $this->render('user/profile.html.twig', [ - 'user' => $user, - 'userOrganizations' => $userOrganizations, - ]); + return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED); + } + + #[Route('/deactivate/{id}', name: 'deactivate', methods: ['GET'])] + public function userDeactivate(Request $request, EntityManagerInterface $entityManager): Response + { + if ($this->isGranted('ROLE_SUDALYS_ADMIN')) { + $userId = $request->attributes->get('id'); + $user = $entityManager->getRepository(User::class)->find($userId); + if (!$user) { + throw $this->createNotFoundException('User not found'); + } + $user->setIsActive(false); + $entityManager->persist($user); + $entityManager->flush(); + return $this->redirectToRoute('user_dashboard'); + } + return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED); + } + } diff --git a/templates/user/profile.html.twig b/templates/user/profile.html.twig index 3a8d9a1..041ac60 100644 --- a/templates/user/profile.html.twig +++ b/templates/user/profile.html.twig @@ -5,7 +5,7 @@