set admin V3 User
This commit is contained in:
@@ -33,6 +33,53 @@ class AdminController extends AbstractController
|
||||
'controller_name' => 'AdminController',
|
||||
]);
|
||||
}
|
||||
#[Route('/admin/user/disable/{id}', name: 'app_adminUserDisable')]
|
||||
public function disableParticipant(string $id, ParticipantRepository $participantRepository, EntityManagerInterface $entityManager): RedirectResponse
|
||||
{
|
||||
// Récupérer le participant à partir de l'id
|
||||
$participant = $participantRepository->find($id);
|
||||
|
||||
// Vérifier si le participant existe
|
||||
if (!$participant) {
|
||||
$this->addFlash('error', 'Le participant demandé n\'existe pas.');
|
||||
return $this->redirectToRoute('app_adminUser'); // Redirigez vers une liste ou une autre page
|
||||
}
|
||||
|
||||
// Désactiver le participant (par exemple, définir une propriété "isActive" à false)
|
||||
if ($participant->isActif()){
|
||||
$participant->setActif(false);
|
||||
}else{
|
||||
$participant->setActif(true);
|
||||
}
|
||||
|
||||
// Sauvegarder la modification en base de données
|
||||
$entityManager->persist($participant);
|
||||
$entityManager->flush();
|
||||
|
||||
// Ajouter un message de succès et rediriger
|
||||
$this->addFlash('success', 'Participant désactivé avec succès.');
|
||||
return $this->redirectToRoute('app_adminUser');
|
||||
}
|
||||
#[Route('/admin/user/delete/{id}', name: 'app_adminUserDelete')]
|
||||
public function deleteUser(string $id, ParticipantRepository $participantRepository, EntityManagerInterface $entityManager): RedirectResponse
|
||||
{
|
||||
// Récupérer l'utilisateur ou le participant à partir de l'id
|
||||
$participant = $participantRepository->find($id);
|
||||
|
||||
// Vérifier si l'utilisateur existe
|
||||
if (!$participant) {
|
||||
$this->addFlash('error', 'L\'utilisateur demandé n\'existe pas.');
|
||||
return $this->redirectToRoute('app_adminUser'); // Redirigez vers une liste ou une autre page
|
||||
}
|
||||
|
||||
// Supprimer l'utilisateur
|
||||
$entityManager->remove($participant);
|
||||
$entityManager->flush();
|
||||
|
||||
// Ajouter un message de succès et rediriger
|
||||
$this->addFlash('success', 'Utilisateur supprimé avec succès.');
|
||||
return $this->redirectToRoute('app_adminUser'); // Redirigez vers la liste des utilisateurs
|
||||
}
|
||||
#[Route('/admin/user/import', name: 'participant_import', methods: ['POST'])]
|
||||
public function import(Request $request, EntityManagerInterface $em): Response
|
||||
{
|
||||
@@ -44,30 +91,32 @@ class AdminController extends AbstractController
|
||||
$participant = new Participant();
|
||||
$participant->setNom($row[0]);
|
||||
$participant->setPrenom($row[1]);
|
||||
$participant->setTelephone($row[2]);
|
||||
$participant->setEmail($row[3]);
|
||||
$participant->setAdministrateur((bool)$row[4]);
|
||||
$participant->setActif((bool)$row[5]);
|
||||
$participant->setRoles(explode('|', $row[6]));
|
||||
$participant->setPassword(password_hash($row[7], PASSWORD_BCRYPT));
|
||||
$participant->setPseudo($row[2]);
|
||||
$participant->setTelephone($row[3]);
|
||||
$participant->setEmail($row[4]);
|
||||
$participant->setAdministrateur((bool)$row[5]);
|
||||
$participant->setActif((bool)$row[6]);
|
||||
$participant->setRoles(explode('|', $row[7]));
|
||||
$participant->setPassword(password_hash($row[8], PASSWORD_BCRYPT));
|
||||
$em->persist($participant);
|
||||
}
|
||||
$em->flush();
|
||||
}
|
||||
return $this->redirectToRoute('participant_index');
|
||||
return $this->redirectToRoute('app_adminUser');
|
||||
}
|
||||
#[Route('/admin/user/export', name: 'participant_export')]
|
||||
public function export(ParticipantRepository $participantRepository): Response
|
||||
{
|
||||
$participants = $participantRepository->findAll();
|
||||
$csv = "Nom,Prénom,Téléphone,Email,Administrateur,Actif,Rôles,Password\n";
|
||||
$csv = "Nom,Prénom,Pseudo,Téléphone,Email,Administrateur,Actif,Rôles,Password\n";
|
||||
foreach ($participants as $participant) {
|
||||
$csv .= sprintf(
|
||||
"%s,%s,%s,%s,%s,%s,%s,%s\n",
|
||||
"%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
|
||||
$participant->getNom(),
|
||||
$participant->getPrenom(),
|
||||
$participant->getPseudo(),
|
||||
$participant->getTelephone(),
|
||||
$participant->getMail(),
|
||||
$participant->getEmail(),
|
||||
$participant->isAdministrateur() ? '1' : '0',
|
||||
$participant->isActif() ? '1' : '0',
|
||||
implode('|', $participant->getRoles()),
|
||||
@@ -77,7 +126,6 @@ class AdminController extends AbstractController
|
||||
$response = new Response($csv);
|
||||
$response->headers->set('Content-Type', 'text/csv');
|
||||
$response->headers->set('Content-Disposition', 'attachment;filename="participants.csv"');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class UserProvider implements UserProviderInterface
|
||||
?? $this->entityManager->getRepository(Participant::class)
|
||||
->findOneBy(['pseudo' => $username]); // Ou par pseudo
|
||||
|
||||
if (!$user) {
|
||||
if (!$user || $user->isActif()) {
|
||||
throw new UsernameNotFoundException('Utilisateur non trouvé');
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<tr>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Prénom</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Pseudo</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Téléphone</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Administrateur</th>
|
||||
@@ -54,8 +55,9 @@
|
||||
<tr>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.nom }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.prenom }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.pseudo }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.telephone }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.mail }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.email }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||
{{ participant.administrateur ? 'Oui' : 'Non' }}
|
||||
</td>
|
||||
@@ -66,8 +68,10 @@
|
||||
{{ participant.roles|join(', ') }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<a href="{{ path('participant_edit', {'id': participant.id}) }}" class="text-indigo-600 hover:text-indigo-900">Modifier</a>
|
||||
<a href="{{ path('participant_delete', {'id': participant.id}) }}" class="text-red-600 hover:text-red-900 ml-4">Supprimer</a>
|
||||
<a href="{{ path('app_adminUserDisable', {'id': participant.idParticipant}) }}" class="text-indigo-600 hover:text-indigo-900">
|
||||
{{ participant.actif ? 'Activer' : 'Désactiver' }}
|
||||
</a>
|
||||
<a href="{{ path('app_adminUserDelete', {'id': participant.idParticipant}) }}" class="text-red-600 hover:text-red-900 ml-4">Supprimer</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
|
||||
Reference in New Issue
Block a user