create user
This commit is contained in:
parent
3d832b4280
commit
52f3d2a3de
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1>Gestion Utilisateurs</h1>
|
||||
{% if is_granted('ROLE_SUPER_ADMIN') %}
|
||||
{# <a href="{{ path('user_new') }}" class="btn btn-primary">Ajouter un utilisateur</a>#}
|
||||
<a href="{{ path('user_new') }}" class="btn btn-primary">Ajouter un utilisateur</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue