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 476854a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 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
12 changes: 11 additions & 1 deletion src/Security/UserNotifier.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
<?php declare(strict_types=1);

/*
* This file is part of Packagist.
*
* (c) Jordi Boggiano <[email protected]>
* Nils Adermann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\Security;

Expand Down

0 comments on commit 476854a

Please sign in to comment.