feat: update profile in buspro without the teamer's password

This commit is contained in:
fromme committed 2026-10-16 08:59:39 +02:00
1 parent 18fb3382c6
commit c16e4bf53f
3 files changed
+187 -8

No files matched your search

@@ -4,6 +4,9 @@ namespace App\Controller\Teamer\Profile;
use App\BusProNet\ApiClient;
use App\BusProNet\ApiClientException;
use App\BusProNet\Model\NotificationResponse;
use App\BusProNet\Model\ProfileUpdateResponse;
use App\BusProNet\ResponseParserException;
use App\Entity\Teamer;
use App\Entity\Upload;
use App\Entity\User;
@@ -59,12 +62,7 @@ class IndexController extends AbstractController
$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) {
}
$this->updateBusProProfile($user);
// Saving the full profile form is a stronger statement than ticking the
// confirmation box, so it clears the verification check too.
@@ -88,6 +86,44 @@ class IndexController extends AbstractController
]);
}
/**
* The local save does not depend on BusPro: a failed write is logged, and the teamer's data
* is kept here either way.
*/
private function updateBusProProfile(User $user): void
{
$context = [
'user_id' => $user->getId(),
'bus_pro_address_id' => $user->getBusProAddressId(),
'bus_pro_person_id' => $user->getBusProPersonId(),
];
if (null === $user->getBusProAddressId() || null === $user->getBusProPersonId()) {
$this->logger->warning('Skip BusPro profile update: user has no BusPro IDs', $context);
return;
}
try {
$response = $this->apiClient->updateProfile($user);
} catch (ApiClientException|ResponseParserException $e) {
$this->logger->error('BusPro profile update failed', $context + [
'error_message' => $e->getMessage(),
]);
return;
}
if ($response instanceof NotificationResponse && false === $response->isSuccessful()) {
$this->logger->error('BusPro rejected profile update', $context + [
'bpn_code' => $response->getCode(),
'bpn_message' => $response->getMessage(),
]);
} elseif ($response instanceof ProfileUpdateResponse && false === $response->isUpdated()) {
$this->logger->error('BusPro did not update profile', $context);
}
}
private function updatePhoto(User $user, UploadSessionDto $uploadSession): void
{
$teamer = $user->getTeamer();