Deactivate user
This commit is contained in:
parent
65ff838dd9
commit
c99b575814
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<div class="col-md-10 m-auto p-5">
|
||||
<div class="col d-flex justify-content-between align-items-center ">
|
||||
<h1 class="mb-4">Gestion Utilisateur</h1>
|
||||
<a href="#" class="btn btn-danger">Désactiver</a>
|
||||
<a href="{{ path('user_deactivate', {'id': user.id}) }}" class="btn btn-danger">Désactiver</a>
|
||||
</div>
|
||||
{% include 'elements/userInformation.html.twig' %}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue