documentation and env changes
This commit is contained in:
1 parent
f77f3a9e40
commit
d52eb6bd81
59 files changed
+932
-565
No files matched your search
@@ -21,8 +21,8 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly UserPasswordHasherInterface $hasher,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UserPasswordHasherInterface $passwordHasher,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -37,13 +37,14 @@ class UserController extends AbstractController
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// Form collects only high-level metadata; everything else is defaulted here.
|
||||
$plainPassword = (string) $form->get('plainPassword')->getData();
|
||||
$newUser = new User();
|
||||
$newUser->setEmail($formData->email);
|
||||
$newUser->setDisplayName($formData->displayName);
|
||||
$newUser->setPassword($this->hasher->hashPassword($newUser, $plainPassword));
|
||||
$this->em->persist($newUser);
|
||||
$this->em->flush();
|
||||
$newUser->setPassword($this->passwordHasher->hashPassword($newUser, $plainPassword));
|
||||
$this->entityManager->persist($newUser);
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'User account created.');
|
||||
return $this->redirectToRoute('admin_users');
|
||||
}
|
||||
@@ -67,6 +68,7 @@ class UserController extends AbstractController
|
||||
/** @var User|null $current */
|
||||
$current = $this->getUser();
|
||||
if ($current && $target->getId() === $current->getId()) {
|
||||
// Protect against accidental lockouts by blocking self-deletes.
|
||||
$this->addFlash('danger', 'You cannot delete your own account.');
|
||||
return $this->redirectToRoute('admin_users');
|
||||
}
|
||||
@@ -76,8 +78,8 @@ class UserController extends AbstractController
|
||||
return $this->redirectToRoute('admin_users');
|
||||
}
|
||||
|
||||
$this->em->remove($target);
|
||||
$this->em->flush();
|
||||
$this->entityManager->remove($target);
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'User deleted.');
|
||||
|
||||
return $this->redirectToRoute('admin_users');
|
||||
@@ -102,14 +104,15 @@ class UserController extends AbstractController
|
||||
$isModerator = in_array('ROLE_MODERATOR', $roles, true);
|
||||
|
||||
if ($isModerator) {
|
||||
// Toggle-style UX: hitting the endpoint again demotes the moderator.
|
||||
$filtered = array_values(array_filter($roles, static fn(string $role) => $role !== 'ROLE_MODERATOR'));
|
||||
$target->setRoles($filtered);
|
||||
$this->em->flush();
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Moderator privileges removed.');
|
||||
} else {
|
||||
$roles[] = 'ROLE_MODERATOR';
|
||||
$target->setRoles(array_values(array_unique($roles)));
|
||||
$this->em->flush();
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'User promoted to moderator.');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user