This commit is contained in:
jleroy2023
2024-11-20 14:49:09 +01:00
parent 21be9ebb52
commit 5b6b44ab9d
5 changed files with 70 additions and 48 deletions

View File

@@ -175,59 +175,64 @@ class AdminController extends AbstractController
#[Route('/admin/user/import', name: 'participant_import', methods: ['POST'])]
public function import(Request $request, EntityManagerInterface $em, MailerInterface $mailer, UrlGeneratorInterface $urlGenerator): RedirectResponse
{
$file = $request->files->get('csv_file');
if ($file) {
$csvData = array_map('str_getcsv', file($file->getPathname()));
foreach ($csvData as $index => $row) {
if ($index === 0) continue;
$participant = new Participant();
$participant->setNom($row[0]);
$participant->setPrenom($row[1]);
$participant->setPseudo($row[2]);
$participant->setTelephone($row[3]);
$participant->setEmail($row[4]);
$participant->setAdministrateur(false);
$participant->setActif(false);
$participant->setRoles(explode('|', $row[7]));
$participant->setPassword(password_hash("aChanger44!", PASSWORD_BCRYPT));
$em->persist($participant);
try{
$file = $request->files->get('csv_file');
if ($file) {
$csvData = array_map('str_getcsv', file($file->getPathname()));
foreach ($csvData as $index => $row) {
if ($index === 0) continue;
$participant = new Participant();
$participant->setNom($row[0]);
$participant->setPrenom($row[1]);
$participant->setPseudo($row[2]);
$participant->setTelephone($row[3]);
$participant->setEmail($row[4]);
$participant->setAdministrateur(false);
$participant->setActif(false);
$participant->setRoles(explode('|', $row[7]));
$participant->setPassword(password_hash("aChanger44!", PASSWORD_BCRYPT));
$em->persist($participant);
// Générer un token unique
$token = bin2hex(random_bytes(32));
// Générer un token unique
$token = bin2hex(random_bytes(32));
// Enregistrer le token dans la base de données
$passwordResetToken = new PasswordResetToken();
$passwordResetToken->setToken($token)
->setEmail($participant->getEmail())
->setCreatedAt(new \DateTime());
// Enregistrer le token dans la base de données
$passwordResetToken = new PasswordResetToken();
$passwordResetToken->setToken($token)
->setEmail($participant->getEmail())
->setCreatedAt(new \DateTime());
$em->persist($passwordResetToken);
$em->persist($passwordResetToken);
// Générer un lien de réinitialisation
$resetLink = $urlGenerator->generate(
'app_password_reset',
['token' => $token],
UrlGeneratorInterface::ABSOLUTE_URL
);
// Générer un lien de réinitialisation
$resetLink = $urlGenerator->generate(
'app_password_reset',
['token' => $token],
UrlGeneratorInterface::ABSOLUTE_URL
);
// Envoyer un email de notification
$email = (new Email())
->from('contact@sortir.com')
->to($participant->getEmail())
->subject('Sortir.com | Bienvenue sur notre site !')
->html("
// Envoyer un email de notification
$email = (new Email())
->from('contact@sortir.com')
->to($participant->getEmail())
->subject('Sortir.com | Bienvenue sur notre site !')
->html("
<h1>Bonjour $row[2],</h1>
<p>Un administrateur du site vous a créé un compte !</p>
<p>Terminer la création de cotre compte : <a href='$resetLink' target='_blank'>Sortir.com</a></p>
<p>Toute l'équipe de Sortir vous souhaite la bienvenue !</p>
");
$mailer->send($email);
$mailer->send($email);
}
$em->flush();
}
$em->flush();
return $this->redirectToRoute('app_adminUser');
}catch(\Exception $e){
$this->addFlash('error', "Votre fichier contient des erreurs : " . $e->getMessage());
return $this->redirectToRoute('app_adminUser');
}
return $this->redirectToRoute('app_adminUser');
}
#[Route('/admin/user/export', name: 'participant_export')]
public function export(ParticipantRepository $participantRepository): Response