WIP: Implement profile editing

This commit is contained in:
Björn Fromme
2023-09-17 19:36:18 +02:00
parent 97c5a686af
commit bfc5e5e242
17 changed files with 498 additions and 18 deletions
@@ -0,0 +1,57 @@
<?php
namespace App\Controller\Teamer;
use App\BusProNet\ApiClient;
use App\BusProNet\ApiClientException;
use App\Entity\Teamer;
use App\Entity\User;
use App\Form\ProfileType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class ProfileController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly ApiClient $apiClient
) {
}
#[Route('/teamer/profile', name: 'app_teamer_profile')]
#[IsGranted('ROLE_TEAMER')]
public function index(Request $request): Response
{
/** @var User $user */
$user = $this->getUser();
$teamer = $user->getTeamer();
if (null === $teamer) {
$teamer = new Teamer();
$user->setTeamer($teamer);
$this->entityManager->persist($teamer);
}
$form = $this->createForm(ProfileType::class, $teamer);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$bpnPassword = $request->getSession()->get('bpn_password');
$this->apiClient->updateProfile($user, $bpnPassword);
$this->entityManager->flush();
} catch (ApiClientException $e) {
}
return $this->redirectToRoute('app_teamer_profile');
}
return $this->render('teamer/profile.html.twig', [
'form' => $form->createView(),
]);
}
}