feat: profile page for administrative users and muting of notifications

This commit is contained in:
Björn Fromme
2024-05-16 11:19:37 +02:00
parent b761480ffe
commit f43b47e987
9 changed files with 164 additions and 0 deletions
@@ -0,0 +1,47 @@
<?php
namespace App\Controller\Administrative;
use App\Entity\User;
use App\Form\UserProfileType;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class ProfileController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/administrative/profile', name: 'app_administrative_profile_index')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Request $request): Response
{
/** @var User $user */
$user = $this->getUser();
$form = $this->createForm(UserProfileType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->flush();
$this->addFlash('success', 'Deine Daten wurden aktualisiert');
$this->logger->info('Update user profile');
return $this->redirectToRoute($user->getDefaultRoute());
}
return $this->render('administrative/profile/index.html.twig', [
'user' => $user,
'form' => $form->createView(),
]);
}
}