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 33870f0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,26 @@ public function editAction(Request $request, UserNotifier $userNotifier): Respon
}

$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_filter([
$oldEmail !== $user->getEmail() ? 'email' : null,
$oldUsername !== $user->getUsername() ? 'username' : null,
]);

$diffs = array_intersect(array_keys($changeSet), ['email', 'username']);

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 33870f0

Please sign in to comment.