Skip to content

Commit

Permalink
Rebase main
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan2Shrek committed Mar 19, 2024
1 parent 3255ea8 commit 4c47443
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,28 @@ public function editAction(Request $request, UserNotifier $userNotifier): Respon
if (!$user instanceof User) {
throw $this->createAccessDeniedException('This user does not have access to this section.');
}

$oldEmail = $user->getEmail();
$oldUsername = $user->getUsername();
$form = $this->createForm(ProfileFormType::class, $user);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$uow = $this->getEM()->getUnitOfWork();
$uow->computeChangeSets();
$changeSet = $uow->getEntityChangeSet($user);

$diffs = array_intersect(array_keys($changeSet), ['email', 'username']);
$diffs = array_filter([
$oldEmail !== $user->getEmail() ? 'email' : null,
$oldUsername !== $user->getUsername() ? 'username' : null,
]);

if (!empty($diffs) && $user instanceof User) {
if (!empty($diffs)) {
$reason = sprintf('Your %s has been changed', implode(' and ', $diffs));
$userNotifier->notifyChange($changeSet['email'][0] ?? $user->getEmail(), $reason);
}

if ($oldEmail !== $user->getEmail()) {
$user->resetPasswordRequest();
if ($oldEmail !== $user->getEmail()) {
$userNotifier->notifyChange($oldEmail, $reason);
$user->resetPasswordRequest();
}

$userNotifier->notifyChange($user->getEmail(), $reason);
}

$this->getEM()->persist($user);
Expand Down

0 comments on commit 4c47443

Please sign in to comment.