forked from KnpLabs/KnpUserBundle
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix for #2667: put email-update-confirmation code into separate controller #2669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
XWB
merged 4 commits into
FriendsOfSymfony:master
from
azine:issue/2667-configuration-dependency-problem-with-confirm-updated-email-address-and-profile-controller
Dec 27, 2017
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f35defb
fix for #2667: put email-update-confirmation code into separate contr…
azine 58e8f40
Merge branch 'master' into issue/2667-configuration-dependency-proble…
azine 92481ce
Merge branch 'master' into issue/2667-configuration-dependency-proble…
azine cc7ab03
synchronize canonical value of email when updating email with confirm…
azine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the FOSUserBundle package. | ||
| * | ||
| * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace FOS\UserBundle\Controller; | ||
|
|
||
| use FOS\UserBundle\Event\UserEvent; | ||
| use FOS\UserBundle\FOSUserEvents; | ||
| use FOS\UserBundle\Model\User; | ||
| use FOS\UserBundle\Model\UserInterface; | ||
| use FOS\UserBundle\Model\UserManagerInterface; | ||
| use FOS\UserBundle\Services\EmailConfirmation\EmailUpdateConfirmation; | ||
| use FOS\UserBundle\Util\CanonicalFieldsUpdater; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
| use Symfony\Component\Translation\TranslatorInterface; | ||
|
|
||
| /** | ||
| * Controller managing the confirmation of changed user email. | ||
| * | ||
| * @author Dominik Businger <git@azine.me> | ||
| */ | ||
| class ConfirmEmailUpdateController extends AbstractController | ||
| { | ||
| /** | ||
| * @var EventDispatcherInterface | ||
| */ | ||
| private $eventDispatcher; | ||
|
|
||
| /** | ||
| * @var UserManagerInterface | ||
| */ | ||
| private $userManager; | ||
|
|
||
| /** | ||
| * @var EmailUpdateConfirmation | ||
| */ | ||
| private $emailUpdateConfirmation; | ||
|
|
||
| /** | ||
| * @var TranslatorInterface | ||
| */ | ||
| private $translator; | ||
| /** | ||
| * @var CanonicalFieldsUpdater | ||
| */ | ||
| private $canonicalFieldsUpdater; | ||
|
|
||
| /** | ||
| * @param EventDispatcherInterface $eventDispatcher | ||
| * @param UserManagerInterface $userManager | ||
| * @param EmailUpdateConfirmation $emailUpdateConfirmation | ||
| * @param TranslatorInterface $translator | ||
| * @param CanonicalFieldsUpdater $canonicalFieldsUpdater | ||
| */ | ||
| public function __construct(EventDispatcherInterface $eventDispatcher, UserManagerInterface $userManager, EmailUpdateConfirmation $emailUpdateConfirmation, TranslatorInterface $translator, CanonicalFieldsUpdater $canonicalFieldsUpdater) | ||
| { | ||
| $this->eventDispatcher = $eventDispatcher; | ||
| $this->userManager = $userManager; | ||
| $this->emailUpdateConfirmation = $emailUpdateConfirmation; | ||
| $this->translator = $translator; | ||
| $this->canonicalFieldsUpdater = $canonicalFieldsUpdater; | ||
| } | ||
|
|
||
| /** | ||
| * Confirm user`s email update. | ||
| * | ||
| * @param Request $request | ||
| * @param string $token | ||
| * | ||
| * @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
| */ | ||
| public function confirmEmailUpdateAction(Request $request, $token) | ||
| { | ||
| /** @var User $user */ | ||
| $user = $this->userManager->findUserByConfirmationToken($token); | ||
|
|
||
| // If user was not found throw 404 exception | ||
| if (!$user) { | ||
| throw $this->createNotFoundException($this->translator->trans('email_update.error.message', array(), 'FOSUserBundle')); | ||
| } | ||
|
|
||
| // Show invalid token message if the user id found via token does not match the current users id (e.g. anon. or other user) | ||
| if (!($this->getUser() instanceof UserInterface) || ($user->getId() !== $this->getUser()->getId())) { | ||
| throw new AccessDeniedException($this->translator->trans('email_update.error.message', array(), 'FOSUserBundle')); | ||
| } | ||
|
|
||
| $this->emailUpdateConfirmation->setUser($user); | ||
|
|
||
| $newEmail = $this->emailUpdateConfirmation->fetchEncryptedEmailFromConfirmationLink($request->get('target')); | ||
|
|
||
| // Update user email | ||
| if ($newEmail) { | ||
| $user->setConfirmationToken($this->emailUpdateConfirmation->getEmailConfirmedToken()); | ||
| $user->setEmail($newEmail); | ||
| $user->setEmail($this->canonicalFieldsUpdater->canonicalizeEmail($newEmail)); | ||
| } | ||
|
|
||
| $this->userManager->updateUser($user); | ||
|
|
||
| $event = new UserEvent($user, $request); | ||
| $this->eventDispatcher->dispatch(FOSUserEvents::EMAIL_UPDATE_SUCCESS, $event); | ||
|
|
||
| return $this->redirect($this->generateUrl('fos_user_profile_show')); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
|
|
||
| <container xmlns="http://symfony.com/schema/dic/services" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
|
||
| <services> | ||
| <service id="fos_user.email_encryption" class="FOS\UserBundle\Services\EmailConfirmation\EmailEncryption"> | ||
| <argument type="service" id="validator"/> | ||
| <argument>%fos_user.email_update_confirmation.cypher_method%</argument> | ||
| </service> | ||
|
|
||
| <service id="fos_user.email_update_confirmation" class="FOS\UserBundle\Services\EmailConfirmation\EmailUpdateConfirmation"> | ||
| <argument type="service" id="router" /> | ||
| <argument type="service" id="fos_user.util.token_generator" /> | ||
| <argument type="service" id="fos_user.mailer" /> | ||
| <argument type="service" id="fos_user.email_encryption" /> | ||
| <argument type="service" id="event_dispatcher" /> | ||
| </service> | ||
|
|
||
| <service id="fos_user.email_update_listener" class="FOS\UserBundle\Doctrine\EmailUpdateListener" public="false"> | ||
| <argument type="service" id="fos_user.email_update_confirmation"/> | ||
| <argument type="service" id="request_stack" /> | ||
| <argument type="service" id="fos_user.util.canonical_fields_updater" /> | ||
| <tag name="doctrine.event_listener" event="preUpdate" lazy="true" /> | ||
| </service> | ||
|
|
||
| <service id="fos_user.confirm.email.update.controller" class="FOS\UserBundle\Controller\ConfirmEmailUpdateController" public="true"> | ||
| <argument type="service" id="event_dispatcher" /> | ||
| <argument type="service" id="fos_user.user_manager" /> | ||
| <argument type="service" id="fos_user.email_update_confirmation" /> | ||
| <argument type="service" id="translator" /> | ||
| <argument type="service" id="fos_user.util.canonical_fields_updater" /> | ||
| </service> | ||
|
|
||
| </services> | ||
|
|
||
| </container> |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed typo:
fos_user.profile.controllervs.fos_user.profiler.controller