Change code to make first user an admin so they have access to reference editor
This commit is contained in:
parent
35748e6db4
commit
e0309874d4
@ -20,6 +20,11 @@ class RegistrationController extends AbstractController
|
|||||||
|
|
||||||
$form = $this->createForm(RegistrationFormType::class, $user);
|
$form = $this->createForm(RegistrationFormType::class, $user);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
$role = ['ROLE_USER'];
|
||||||
|
|
||||||
|
if ($entityManager->getRepository(User::class)->getUserCount() == 0) {
|
||||||
|
$role = ['ROLE_ADMIN'];
|
||||||
|
}
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
// encode the plain password
|
// encode the plain password
|
||||||
@ -28,8 +33,8 @@ class RegistrationController extends AbstractController
|
|||||||
$user,
|
$user,
|
||||||
$form->get('plainPassword')->getData()
|
$form->get('plainPassword')->getData()
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
->setRoles(['ROLE_USER']);
|
$user->setRoles($role);
|
||||||
|
|
||||||
$entityManager->persist($user);
|
$entityManager->persist($user);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
@ -33,6 +33,15 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
|
|||||||
$this->getEntityManager()->flush();
|
$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
|
// * @return User[] Returns an array of User objects
|
||||||
// */
|
// */
|
||||||
|
Loading…
Reference in New Issue
Block a user