Change code to make first user an admin so they have access to reference editor

This commit is contained in:
Ryan Prather 2024-05-24 00:49:56 -04:00
parent 35748e6db4
commit e0309874d4
2 changed files with 16 additions and 2 deletions

View File

@ -20,6 +20,11 @@ class RegistrationController extends AbstractController
$form = $this->createForm(RegistrationFormType::class, $user);
$form->handleRequest($request);
$role = ['ROLE_USER'];
if ($entityManager->getRepository(User::class)->getUserCount() == 0) {
$role = ['ROLE_ADMIN'];
}
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
@ -28,8 +33,8 @@ class RegistrationController extends AbstractController
$user,
$form->get('plainPassword')->getData()
)
)
->setRoles(['ROLE_USER']);
);
$user->setRoles($role);
$entityManager->persist($user);
$entityManager->flush();

View File

@ -33,6 +33,15 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
$this->getEntityManager()->flush();
}
public function getUserCount(): int
{
return $this->createQueryBuilder('u')
->select('COUNT(u.id)')
->getQuery()
->getSingleScalarResult()
;
}
// /**
// * @return User[] Returns an array of User objects
// */