diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index dc00825..e0dd0b8 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -142,4 +142,50 @@ class UserController extends AbstractController } throw $this->createAccessDeniedException(self::ACCESS_DENIED); } + + #[Route('/new', name: 'new', methods: ['GET', 'POST'])] + public function new(Request $request): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); + if ($this->userService->hasAccessTo($actingUser)) { + $user = new User(); + $form = $this->createForm(UserForm::class, $user); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $orgId = $request->query->get('organizationId'); + // Handle file upload + $logoFile = $form->get('pictureUrl')->getData(); + + if ($logoFile) { + $this->userService->handleProfilePicture($user, $logoFile); + + } + if ($orgId) { + $org = $this->entityManager->getRepository(Organizations::class)->find($orgId); + if ($org) { + $uo = new UsersOrganizations(); + $uo->setUsers($user); + $uo->setOrganization($org); + $this->entityManager->persist($uo); + $this->actionService->createAction("Create new user", $user, $orgId, $user->getUserIdentifier()." for organization ".$org->getName()); + } + } + else{ + $this->actionService->createAction("Create new user", $user, null, $user->getUserIdentifier()); + } + $this->entityManager->flush(); + + + return $this->redirectToRoute('user_show', ['id' => $user->getId()]); + } + + return $this->render('user/new.html.twig', [ + 'user' => $user, + 'form' => $form->createView(), + ]); + } + throw $this->createAccessDeniedException(self::ACCESS_DENIED); + } } diff --git a/templates/user/index.html.twig b/templates/user/index.html.twig index 3f0012c..c6ca890 100644 --- a/templates/user/index.html.twig +++ b/templates/user/index.html.twig @@ -7,7 +7,7 @@