From 8bb87890cbd872c870f7bd146922906f6e8ddf5c Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 16 Feb 2018 13:18:09 +0100 Subject: [PATCH] Revert the email update confirmation feature The implementation is far from being in a state allowing to release it. The feature might be accepted again in the future with a different implementation, but the bundle should have releases without waiting for that. --- Changelog.md | 1 - Controller/ConfirmEmailUpdateController.php | 90 -------- DependencyInjection/Configuration.php | 8 - DependencyInjection/FOSUserExtension.php | 13 +- Doctrine/EmailUpdateListener.php | 87 -------- EventListener/FlashListener.php | 17 -- FOSUserEvents.php | 18 -- Mailer/Mailer.php | 18 -- Mailer/MailerInterface.php | 9 - Mailer/NoopMailer.php | 8 - Mailer/TwigSwiftMailer.php | 20 -- Resources/config/email_confirmation.xml | 1 - Resources/config/mailer.xml | 3 - Resources/config/profile_email_update.xml | 38 ---- Resources/config/routing/all.xml | 3 - Resources/config/routing/update_email.xml | 11 - Resources/doc/configuration_reference.rst | 6 +- Resources/doc/emails.rst | 29 --- Resources/translations/FOSUserBundle.de.yml | 15 -- Resources/translations/FOSUserBundle.en.yml | 16 -- Resources/translations/FOSUserBundle.fr.yml | 17 +- Resources/translations/FOSUserBundle.ru.yml | 16 -- .../email_update_confirmation.txt.twig | 9 - .../EmailConfirmation/EmailEncryption.php | 190 ----------------- .../EmailUpdateConfirmation.php | 196 ------------------ .../Interfaces/EmailEncryptionInterface.php | 44 ---- .../EmailUpdateConfirmationInterface.php | 48 ----- .../FOSUserExtensionTest.php | 38 +--- Tests/EventListener/FlashListenerTest.php | 5 - Tests/Routing/RoutingTest.php | 5 - Tests/Services/EmailEncryptionTest.php | 104 ---------- .../Services/EmailUpdateConfirmationTest.php | 88 -------- Upgrade.md | 11 - 33 files changed, 5 insertions(+), 1177 deletions(-) delete mode 100644 Controller/ConfirmEmailUpdateController.php delete mode 100644 Doctrine/EmailUpdateListener.php delete mode 100644 Resources/config/profile_email_update.xml delete mode 100644 Resources/config/routing/update_email.xml delete mode 100644 Resources/views/Profile/email_update_confirmation.txt.twig delete mode 100644 Services/EmailConfirmation/EmailEncryption.php delete mode 100644 Services/EmailConfirmation/EmailUpdateConfirmation.php delete mode 100644 Services/EmailConfirmation/Interfaces/EmailEncryptionInterface.php delete mode 100644 Services/EmailConfirmation/Interfaces/EmailUpdateConfirmationInterface.php delete mode 100644 Tests/Services/EmailEncryptionTest.php delete mode 100644 Tests/Services/EmailUpdateConfirmationTest.php diff --git a/Changelog.md b/Changelog.md index d65a737098..03b59b9228 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,7 +6,6 @@ Changelog * Add Symfony 4 compatibility. * Redirect to login when requesting resetting password with invalid token. * Added autocomplete hints for password inputs. -* Added email update confirmation option. * Fixed several incorrect Turkish translations. ### 2.0.2 (2017-11-29) diff --git a/Controller/ConfirmEmailUpdateController.php b/Controller/ConfirmEmailUpdateController.php deleted file mode 100644 index 1faf8fb2fb..0000000000 --- a/Controller/ConfirmEmailUpdateController.php +++ /dev/null @@ -1,90 +0,0 @@ - - * - * 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\Controller; -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 - */ -class ConfirmEmailUpdateController extends Controller -{ - private $eventDispatcher; - private $userManager; - private $emailUpdateConfirmation; - private $translator; - private $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')); - } -} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 64cb9eca9f..26ed0601f0 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -109,14 +109,6 @@ private function addProfileSection(ArrayNodeDefinition $node) ->end() ->end() ->end() - ->arrayNode('email_update_confirmation') - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultFalse()->end() - ->scalarNode('cypher_method')->defaultNull()->end() - ->scalarNode('email_template')->defaultValue('@FOSUser/Profile/email_update_confirmation.txt.twig')->end() - ->end() - ->end() ->end() ->end() ->end(); diff --git a/DependencyInjection/FOSUserExtension.php b/DependencyInjection/FOSUserExtension.php index 52db11dcc6..e73fc58118 100644 --- a/DependencyInjection/FOSUserExtension.php +++ b/DependencyInjection/FOSUserExtension.php @@ -113,7 +113,7 @@ public function load(array $configs, ContainerBuilder $container) )); if (!empty($config['profile'])) { - $this->loadProfile($config['profile'], $container, $loader, $config['db_driver']); + $this->loadProfile($config['profile'], $container, $loader); } if (!empty($config['registration'])) { @@ -189,20 +189,11 @@ protected function remapParametersNamespaces(array $config, ContainerBuilder $co * @param array $config * @param ContainerBuilder $container * @param XmlFileLoader $loader - * @param string $dbDriver */ - private function loadProfile(array $config, ContainerBuilder $container, XmlFileLoader $loader, $dbDriver) + private function loadProfile(array $config, ContainerBuilder $container, XmlFileLoader $loader) { $loader->load('profile.xml'); - if ($config['email_update_confirmation']['enabled']) { - if ('custom' !== $dbDriver && isset(self::$doctrineDrivers[$dbDriver])) { - $loader->load('profile_email_update.xml'); - } - $container->setParameter('fos_user.email_update_confirmation.template', $config['email_update_confirmation']['email_template']); - $container->setParameter('fos_user.email_update_confirmation.cypher_method', $config['email_update_confirmation']['cypher_method']); - } - $this->remapParametersNamespaces($config, $container, array( 'form' => 'fos_user.profile.form.%s', )); diff --git a/Doctrine/EmailUpdateListener.php b/Doctrine/EmailUpdateListener.php deleted file mode 100644 index 96ec72428d..0000000000 --- a/Doctrine/EmailUpdateListener.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\Doctrine; - -use Doctrine\ORM\Event\PreUpdateEventArgs; -use FOS\UserBundle\Model\UserInterface; -use FOS\UserBundle\Services\EmailConfirmation\EmailUpdateConfirmation; -use FOS\UserBundle\Util\CanonicalFieldsUpdater; -use Symfony\Component\HttpFoundation\RequestStack; - -/** - * Class EmailUpdateListener. - */ -class EmailUpdateListener -{ - /** - * @var EmailUpdateConfirmation - */ - private $emailUpdateConfirmation; - - /** - * @var RequestStack - */ - private $requestStack; - /** - * @var CanonicalFieldsUpdater - */ - private $canonicalFieldsUpdater; - - /** - * Constructor. - * - * @param EmailUpdateConfirmation $emailUpdateConfirmation - * @param RequestStack $requestStack - * @param CanonicalFieldsUpdater $canonicalFieldsUpdater - */ - public function __construct(EmailUpdateConfirmation $emailUpdateConfirmation, RequestStack $requestStack, CanonicalFieldsUpdater $canonicalFieldsUpdater) - { - $this->emailUpdateConfirmation = $emailUpdateConfirmation; - $this->requestStack = $requestStack; - $this->canonicalFieldsUpdater = $canonicalFieldsUpdater; - } - - /** - * Pre update listener based on doctrine common. - * - * @param PreUpdateEventArgs $args - */ - public function preUpdate(PreUpdateEventArgs $args) - { - $object = $args->getObject(); - - if ($object instanceof UserInterface && $args instanceof PreUpdateEventArgs) { - $user = $object; - - if ($user->getConfirmationToken() != $this->emailUpdateConfirmation->getEmailConfirmedToken() && isset($args->getEntityChangeSet()['email'])) { - $oldEmail = $args->getEntityChangeSet()['email'][0]; - $newEmail = $args->getEntityChangeSet()['email'][1]; - $user->setEmail($oldEmail); - $user->setEmailCanonical($this->canonicalFieldsUpdater->canonicalizeEmail($oldEmail)); - - // Configure email confirmation - $this->emailUpdateConfirmation->setUser($user); - $this->emailUpdateConfirmation->setEmail($newEmail); - $this->emailUpdateConfirmation->setConfirmationRoute('fos_user_update_email_confirm'); - $this->emailUpdateConfirmation->getMailer()->sendUpdateEmailConfirmation( - $user, - $this->emailUpdateConfirmation->generateConfirmationLink($this->requestStack->getCurrentRequest()), - $newEmail - ); - } - - if ($user->getConfirmationToken() == $this->emailUpdateConfirmation->getEmailConfirmedToken()) { - $user->setConfirmationToken(null); - } - } - } -} diff --git a/EventListener/FlashListener.php b/EventListener/FlashListener.php index 87711edaad..a42c87a836 100644 --- a/EventListener/FlashListener.php +++ b/EventListener/FlashListener.php @@ -30,8 +30,6 @@ class FlashListener implements EventSubscriberInterface FOSUserEvents::PROFILE_EDIT_COMPLETED => 'profile.flash.updated', FOSUserEvents::REGISTRATION_COMPLETED => 'registration.flash.user_created', FOSUserEvents::RESETTING_RESET_COMPLETED => 'resetting.flash.success', - FOSUserEvents::EMAIL_UPDATE_SUCCESS => 'email_update.flash.success', - FOSUserEvents::EMAIL_UPDATE_INITIALIZE => 'email_update.flash.info', ); /** @@ -69,8 +67,6 @@ public static function getSubscribedEvents() FOSUserEvents::PROFILE_EDIT_COMPLETED => 'addSuccessFlash', FOSUserEvents::REGISTRATION_COMPLETED => 'addSuccessFlash', FOSUserEvents::RESETTING_RESET_COMPLETED => 'addSuccessFlash', - FOSUserEvents::EMAIL_UPDATE_SUCCESS => 'addSuccessFlash', - FOSUserEvents::EMAIL_UPDATE_INITIALIZE => 'addInfoFlash', ); } @@ -87,19 +83,6 @@ public function addSuccessFlash(Event $event, $eventName) $this->session->getFlashBag()->add('success', $this->trans(self::$successMessages[$eventName])); } - /** - * @param Event $event - * @param string $eventName - */ - public function addInfoFlash(Event $event, $eventName) - { - if (!isset(self::$successMessages[$eventName])) { - throw new \InvalidArgumentException('This event does not correspond to a known flash message'); - } - - $this->session->getFlashBag()->add('info', $this->trans(self::$successMessages[$eventName])); - } - /** * @param string$message * @param array $params diff --git a/FOSUserEvents.php b/FOSUserEvents.php index f19bf2e19e..274760e82d 100644 --- a/FOSUserEvents.php +++ b/FOSUserEvents.php @@ -318,22 +318,4 @@ final class FOSUserEvents * @Event("FOS\UserBundle\Event\UserEvent") */ const USER_DEMOTED = 'fos_user.user.demoted'; - - /** - * The EMAIL_UPDATE_INITIALIZE event occurs when the email update process is initialized. - * - * This event allows you to access the user and to add some behaviour after email update is initialized.. - * - * @Event("FOS\UserBundle\Event\UserEvent") - */ - const EMAIL_UPDATE_INITIALIZE = 'fos_user.update_email.initialize'; - - /** - * The EMAIL_UPDATE_SUCCESS event occurs when the email was successfully updated through confirmation link. - * - * This event allows you to access the user and to add some behaviour after email was confirmed and updated.. - * - * @Event("FOS\UserBundle\Event\UserEvent") - */ - const EMAIL_UPDATE_SUCCESS = 'fos_user.update_email.success'; } diff --git a/Mailer/Mailer.php b/Mailer/Mailer.php index a953d5dc62..8f9e537a70 100644 --- a/Mailer/Mailer.php +++ b/Mailer/Mailer.php @@ -84,24 +84,6 @@ public function sendResettingEmailMessage(UserInterface $user) $this->sendEmailMessage($rendered, $this->parameters['from_email']['resetting'], (string) $user->getEmail()); } - /** - * Send confirmation link to specified new user email. - * - * @param UserInterface $user - * @param string $confirmationUrl - * @param string $toEmail - */ - public function sendUpdateEmailConfirmation(UserInterface $user, $confirmationUrl, $toEmail) - { - $template = $this->parameters['email_updating.template']; - $rendered = $this->templating->render($template, array( - 'user' => $user, - 'confirmationUrl' => $confirmationUrl, - )); - - $this->sendEmailMessage($rendered, $this->parameters['from_email']['resetting'], $toEmail); - } - /** * @param string $renderedTemplate * @param array|string $fromEmail diff --git a/Mailer/MailerInterface.php b/Mailer/MailerInterface.php index d5c10e16e6..55f281b11e 100644 --- a/Mailer/MailerInterface.php +++ b/Mailer/MailerInterface.php @@ -31,13 +31,4 @@ public function sendConfirmationEmailMessage(UserInterface $user); * @param UserInterface $user */ public function sendResettingEmailMessage(UserInterface $user); - - /** - * Send an email to a user to confirm the changed email address. - * - * @param UserInterface $user - * @param string $confirmationUrl - * @param string $toEmail - */ - public function sendUpdateEmailConfirmation(UserInterface $user, $confirmationUrl, $toEmail); } diff --git a/Mailer/NoopMailer.php b/Mailer/NoopMailer.php index 6092598512..4833cd8af8 100644 --- a/Mailer/NoopMailer.php +++ b/Mailer/NoopMailer.php @@ -37,12 +37,4 @@ public function sendResettingEmailMessage(UserInterface $user) { // nothing happens. } - - /** - * {@inheritdoc} - */ - public function sendUpdateEmailConfirmation(UserInterface $user, $confirmationUrl, $toEmail) - { - // nothing happens. - } } diff --git a/Mailer/TwigSwiftMailer.php b/Mailer/TwigSwiftMailer.php index 83f7ad25bc..cad3696828 100644 --- a/Mailer/TwigSwiftMailer.php +++ b/Mailer/TwigSwiftMailer.php @@ -87,26 +87,6 @@ public function sendResettingEmailMessage(UserInterface $user) $this->sendMessage($template, $context, $this->parameters['from_email']['resetting'], (string) $user->getEmail()); } - /** - * Send confirmation link to specified new user email. - * - * @param UserInterface $user - * @param $confirmationUrl - * @param $toEmail - * - * @return bool - */ - public function sendUpdateEmailConfirmation(UserInterface $user, $confirmationUrl, $toEmail) - { - $template = $this->parameters['template']['email_updating']; - $context = array( - 'user' => $user, - 'confirmationUrl' => $confirmationUrl, - ); - - $this->sendMessage($template, $context, $this->parameters['from_email']['confirmation'], $toEmail); - } - /** * @param string $templateName * @param array $context diff --git a/Resources/config/email_confirmation.xml b/Resources/config/email_confirmation.xml index ff3be6c9e7..281a6bb6b0 100644 --- a/Resources/config/email_confirmation.xml +++ b/Resources/config/email_confirmation.xml @@ -12,7 +12,6 @@ - diff --git a/Resources/config/mailer.xml b/Resources/config/mailer.xml index b35313e308..d16278dade 100644 --- a/Resources/config/mailer.xml +++ b/Resources/config/mailer.xml @@ -7,7 +7,6 @@ @FOSUser/Resetting/email.txt.twig @FOSUser/Registration/email.txt.twig - @FOSUser/Profile/email_update_confirmation.txt.twig @@ -18,7 +17,6 @@ %fos_user.registration.confirmation.template% %fos_user.resetting.email.template% - %fos_user.email_update_confirmation.template% %fos_user.registration.confirmation.from_email% %fos_user.resetting.email.from_email% @@ -35,7 +33,6 @@ %fos_user.registration.confirmation.template% %fos_user.resetting.email.template% - %fos_user.email_update_confirmation.template% %fos_user.registration.confirmation.from_email% diff --git a/Resources/config/profile_email_update.xml b/Resources/config/profile_email_update.xml deleted file mode 100644 index 3532f0e96b..0000000000 --- a/Resources/config/profile_email_update.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - %fos_user.email_update_confirmation.cypher_method% - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Resources/config/routing/all.xml b/Resources/config/routing/all.xml index e08f255cae..4000b42db9 100644 --- a/Resources/config/routing/all.xml +++ b/Resources/config/routing/all.xml @@ -18,7 +18,4 @@ - diff --git a/Resources/config/routing/update_email.xml b/Resources/config/routing/update_email.xml deleted file mode 100644 index 87f8664f7e..0000000000 --- a/Resources/config/routing/update_email.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - fos_user.confirm.email.update.controller:confirmEmailUpdateAction - - - diff --git a/Resources/doc/configuration_reference.rst b/Resources/doc/configuration_reference.rst index 5a32e400d4..e26f104bcf 100644 --- a/Resources/doc/configuration_reference.rst +++ b/Resources/doc/configuration_reference.rst @@ -21,11 +21,7 @@ All available configuration options are listed below with their default values. form: type: FOS\UserBundle\Form\Type\ProfileFormType name: fos_user_profile_form - validation_groups: [Profile, Default] - email_update_confirmation: - enabled: false # change to force confirmation of changed email by sending a confirmation link to the new address. - email_template: '@FOSUser/Profile/email_update_confirmation.txt.twig' - cypher_method: null # the cypher method to be used to encrypt/decrypt the email confirmation tokens. If not specified, the first method returned by openssl_get_cipher_methods will be used. See http://php.net/manual/function.openssl-get-cipher-methods.php + validation_groups: [Profile, Default]openssl_get_cipher_methods will be used. See http://php.net/manual/function.openssl-get-cipher-methods.php change_password: form: type: FOS\UserBundle\Form\Type\ChangePasswordFormType diff --git a/Resources/doc/emails.rst b/Resources/doc/emails.rst index a24776439f..5382da55e6 100644 --- a/Resources/doc/emails.rst +++ b/Resources/doc/emails.rst @@ -24,35 +24,6 @@ To enable it, update your configuration as follows: confirmation: enabled: true -Confirmation of Changed Email ------------------------------ - -When a user changes their email address on the edit profile page, -the bundle can send a confirmation email to the new address. The -new address will only be activated / written to the database once -the user clicks on the confirmation link in the confirmation email. - -Requiring email update confirmation is turned off by default. -To enable it, update your configuration as follows: - -.. code-block:: yaml - - # app/config/config.yml - fos_user: - # ... - profile: - email_update_confirmation: - enabled: true - -When clicking the confirmation-link, the user has to be logged in. For the best -user experience it is recommended to protect the url of the route `fos_user_update_email_confirm` -in the security configuration. - -.. code-block:: yaml - security: - access_control: - - { path: "/{YOUR-PREFIX}/profile/confirm-email-update/{token}", roles: IS_AUTHENTICATED_REMEMBERED } - Password Reset -------------- diff --git a/Resources/translations/FOSUserBundle.de.yml b/Resources/translations/FOSUserBundle.de.yml index 3ddbc1820b..8f695361ab 100644 --- a/Resources/translations/FOSUserBundle.de.yml +++ b/Resources/translations/FOSUserBundle.de.yml @@ -27,21 +27,6 @@ change_password: submit: 'Passwort ändern' flash: success: 'Das Passwort wurde geändert.' -email_update: - flash: - info: 'Bitte überprüfen Sie das Postfach der neuen Email-Adresse und klicken Sie den Link im Bestätigungsmail.' - success: 'Email-Adresse wurde erfolgreich aktualisiert.' - error: - message: 'Ungültiger Bestätigungslink. Email-Adresse konnte nicht aktualisiert werden.' - email: - subject: 'Neue Email-Adresse Aktivierung bestätigen.' - message: | - Hallo %username%! - - Um Ihre neue Email-Adresse zu aktivieren, besuchen Sie bitten den folgenden Link: %confirmationUrl% - - Freundliche Grüße, - das Team. registration: check_email: 'Eine E-Mail wurde an %email% gesendet. Sie enthält einen Link, den Sie anklicken müssen, um Ihr Benutzerkonto zu bestätigen.' confirmed: 'Glückwunsch %username%, Ihr Benutzerkonto ist jetzt bestätigt.' diff --git a/Resources/translations/FOSUserBundle.en.yml b/Resources/translations/FOSUserBundle.en.yml index 6e9428dc5c..1aae2955f6 100644 --- a/Resources/translations/FOSUserBundle.en.yml +++ b/Resources/translations/FOSUserBundle.en.yml @@ -31,22 +31,6 @@ change_password: flash: success: 'The password has been changed.' -email_update: - flash: - info: 'Please check the inbox of your new email address and click the link in the confirmation email.' - success: 'E-mail was successfully updated' - error: - message: 'Invalid confirmation link. Can not update the email address.' - email: - subject: 'Confirm the activation of the new email address.' - message: | - Hello %username%! - - To activate your new email address - please visit %confirmationUrl% - - Kind regards, - the Team. - registration: check_email: | An email has been sent to %email%. It contains an activation link you must click to activate your account. diff --git a/Resources/translations/FOSUserBundle.fr.yml b/Resources/translations/FOSUserBundle.fr.yml index 4a798d34fe..e499df19ed 100644 --- a/Resources/translations/FOSUserBundle.fr.yml +++ b/Resources/translations/FOSUserBundle.fr.yml @@ -28,21 +28,6 @@ change_password: flash: success: 'Le mot de passe a été modifié.' -email_update: - flash: - info: 'Un email a été envoyé à votre nouvelle adresse email. Il contient un lien d''activation sur lequel il vous faudra cliquer afin de confirmer l''adresse email.' - success: 'l''e-mail a été mis à jour avec succès.' - error: - message: 'Lien de confirmation invalide. L''email ne peut pas être mis à jour.' - email: - subject: 'Confirmez l''activation de la nouvelle adresse email.' - message: | - Bonjour %username%! - Pour activer votre nouvelle adresse email, merci de vous rendre sur %confirmationUrl% - - Cordialement, - L'équipe - registration: check_email: 'Un e-mail a été envoyé à l''adresse %email%. Il contient un lien d''activation sur lequel il vous faudra cliquer afin d''activer votre compte.' confirmed: 'Félicitations %username%, votre compte est maintenant activé.' @@ -56,7 +41,7 @@ registration: Bonjour %username% ! Pour valider votre compte utilisateur, merci de vous rendre sur %confirmationUrl% - + Ce lien ne peut être utilisé qu'une seule fois pour valider votre compte. Cordialement, diff --git a/Resources/translations/FOSUserBundle.ru.yml b/Resources/translations/FOSUserBundle.ru.yml index c82c7731c6..f4889451e1 100644 --- a/Resources/translations/FOSUserBundle.ru.yml +++ b/Resources/translations/FOSUserBundle.ru.yml @@ -28,22 +28,6 @@ change_password: flash: success: 'Пароль изменен.' -email_update: - flash: - info: 'Пожалуйста, проверьте ваш новый почтовый ящик и перейдите по ссылке из письма для подтверждения изменений' - success: 'Адрес электронной почты изменён' - error: - message: 'Ссылка для подтверждения E-mail не действительна. Не удалось обновить адрес электронной почты' - email: - subject: 'Подтвердите изменение адреса электронной почты.' - message: | - Приветствуем, %username%! - - Для изменения адреса электронной почты пройдите по ссылке %confirmationUrl% - - С наилучшими пожеланиями, - команда сайта. - registration: check_email: 'Письмо отправлено на адрес %email%. В нём содержится ссылка, по которой вы можете подтвердить свою регистрацию.' confirmed: 'Поздравляем %username%, ваш аккаунт подтвержден.' diff --git a/Resources/views/Profile/email_update_confirmation.txt.twig b/Resources/views/Profile/email_update_confirmation.txt.twig deleted file mode 100644 index 03beaec1e1..0000000000 --- a/Resources/views/Profile/email_update_confirmation.txt.twig +++ /dev/null @@ -1,9 +0,0 @@ -{% trans_default_domain 'FOSUserBundle' %} -{% block subject %} -{{ 'email_update.email.subject'|trans }} -{% endblock %} - -{% block body_text %} -{{ 'email_update.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }} -{% endblock %} -{% block body_html %}{% endblock %} diff --git a/Services/EmailConfirmation/EmailEncryption.php b/Services/EmailConfirmation/EmailEncryption.php deleted file mode 100644 index 87be98e08c..0000000000 --- a/Services/EmailConfirmation/EmailEncryption.php +++ /dev/null @@ -1,190 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\Services\EmailConfirmation; - -use FOS\UserBundle\Services\EmailConfirmation\Interfaces\EmailEncryptionInterface; -use Symfony\Component\Validator\Constraints\Email; -use Symfony\Component\Validator\ConstraintViolationList; -use Symfony\Component\Validator\Validator\ValidatorInterface; - -/** - * Class EmailEncryption. - * - * Use this class for encryption/decryption of email value based on specified - * token. - */ -class EmailEncryption implements EmailEncryptionInterface -{ - /** - * @var string - */ - private $encryptionMode; - - /** - * @var string User confirmation token. Use for email encryption - */ - private $userConfirmationToken; - - /** - * @var string Email value to be encrypted - */ - private $email; - - /** - * @var ValidatorInterface - */ - private $validator; - - /** - * EmailEncryption cypher method (see http://php.net/manual/function.openssl-get-cipher-methods.php ). - * - * @param ValidatorInterface $validator - * @param string $mode - */ - public function __construct(ValidatorInterface $validator, $mode = null) - { - $this->validator = $validator; - if (!$mode) { - $mode = openssl_get_cipher_methods(false)[0]; - } - $this->encryptionMode = $mode; - } - - /** - * Encrypt email value with specified user confirmation token. - * - * @return string Encrypted email - */ - public function encryptEmailValue() - { - $iv = openssl_random_pseudo_bytes($this->getIvSize()); - - $encryptedEmail = openssl_encrypt( - $this->email, - $this->encryptionMode, - $this->getConfirmationToken(), - 0, - $iv - ); - - $encryptedEmail = base64_encode($iv.$encryptedEmail); - - return $encryptedEmail; - } - - /** - * Decrypt email value with specified user confirmation token. - * - * @param string $encryptedEmail - * - * @return string Decrypted email - */ - public function decryptEmailValue($encryptedEmail) - { - $b64DecodedEmailHash = base64_decode($encryptedEmail); - $ivSize = $this->getIvSize(); - - // Select IV part from encrypted value - $iv = substr($b64DecodedEmailHash, 0, $ivSize); - - // Select email part from encrypted value - $preparedEncryptedEmail = substr($b64DecodedEmailHash, $ivSize); - - $decryptedEmail = openssl_decrypt( - $preparedEncryptedEmail, - $this->encryptionMode, - $this->getConfirmationToken(), - 0, - $iv - ); - - // Trim decrypted email from nul byte before return - $email = rtrim($decryptedEmail, "\0"); - - /** @var ConstraintViolationList $violationList */ - $violationList = $this->validator->validate($email, new Email()); - if ($violationList->count() > 0) { - throw new \InvalidArgumentException('Wrong email format was provided for decryptEmailValue function'); - } - - return $email; - } - - /** - * Set user confirmation token. Will be used for email encryption/decryption. - * User confirmation token size should be either 16, 24 or 32 byte. - * - * @param string $userConfirmationToken - * - * @return $this - */ - public function setUserConfirmationToken($userConfirmationToken) - { - if (!$userConfirmationToken || !is_string($userConfirmationToken)) { - throw new \InvalidArgumentException( - 'Invalid user confirmation token value.' - ); - } - - $this->userConfirmationToken = $userConfirmationToken; - - return $this; - } - - /** - * Set email value to be encrypted. - * - * @param string $email - * - * @return $this - */ - public function setEmail($email) - { - if (!is_string($email)) { - throw new \InvalidArgumentException( - 'Email to be encrypted should a string. ' - .gettype($email).' given.' - ); - } - - $this->email = trim($email); - - return $this; - } - - /** - * Get confirmation token. - * - * @return string - */ - public function getConfirmationToken() - { - if (!$this->userConfirmationToken) { - throw new \InvalidArgumentException( - 'User confirmation token should be specified.' - ); - } - - // Generate the random binary string based on hashed hexadecimal token - return pack('H*', hash('sha256', $this->userConfirmationToken)); - } - - /** - * Return IV size. - * - * @return int - */ - protected function getIvSize() - { - return openssl_cipher_iv_length($this->encryptionMode); - } -} diff --git a/Services/EmailConfirmation/EmailUpdateConfirmation.php b/Services/EmailConfirmation/EmailUpdateConfirmation.php deleted file mode 100644 index 48327bc34f..0000000000 --- a/Services/EmailConfirmation/EmailUpdateConfirmation.php +++ /dev/null @@ -1,196 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\Services\EmailConfirmation; - -use FOS\UserBundle\Event\UserEvent; -use FOS\UserBundle\FOSUserEvents; -use FOS\UserBundle\Mailer\MailerInterface; -use FOS\UserBundle\Model\UserInterface; -use FOS\UserBundle\Services\EmailConfirmation\Interfaces\EmailEncryptionInterface; -use FOS\UserBundle\Services\EmailConfirmation\Interfaces\EmailUpdateConfirmationInterface; -use FOS\UserBundle\Util\TokenGenerator; -use Symfony\Bundle\FrameworkBundle\Routing\Router; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\RouterInterface; - -class EmailUpdateConfirmation implements EmailUpdateConfirmationInterface -{ - const EMAIL_CONFIRMED = 'email_confirmed'; - - private $mailer; - private $router; - private $tokenGenerator; - private $emailEncryption; - - /** - * @var UserInterface - */ - private $user; - - /** - * @var string Email to be confirmed - */ - private $email; - - /** - * @var string Route for confirmation link - */ - private $confirmationRoute; - private $eventDispatcher; - - public function __construct( - Router $router, - TokenGenerator $tokenGenerator, - MailerInterface $mailer, - EmailEncryptionInterface $emailEncryption, - EventDispatcherInterface $eventDispatcher - ) { - $this->router = $router; - $this->tokenGenerator = $tokenGenerator; - $this->mailer = $mailer; - $this->emailEncryption = $emailEncryption; - $this->eventDispatcher = $eventDispatcher; - } - - /** - * Get $mailer. - * - * @return MailerInterface - */ - public function getMailer() - { - return $this->mailer; - } - - /** - * Generate new confirmation link for new email based on user confirmation - * token and hashed new user email. - * - * @param Request $request - * - * @return string - */ - public function generateConfirmationLink(Request $request) - { - $this->emailEncryption->setUserConfirmationToken( - $this->getUserConfirmationToken() - ); - - $encryptedEmail = $this->emailEncryption->encryptEmailValue(); - - $confirmationParams = array('token' => $this->user->getConfirmationToken(), 'target' => $encryptedEmail); - - $event = new UserEvent($this->user, $request); - $this->eventDispatcher->dispatch(FOSUserEvents::EMAIL_UPDATE_INITIALIZE, $event); - - return $this->router->generate( - $this->confirmationRoute, - $confirmationParams, - RouterInterface::ABSOLUTE_URL - ); - } - - /** - * Fetch email value from hashed part of confirmation link. - * - * @param string $hashedEmail - * - * @return string Encrypted email - */ - public function fetchEncryptedEmailFromConfirmationLink($hashedEmail) - { - //replace spaces with plus sign from hash, which could be replaced in url - $hashedEmail = str_replace(' ', '+', $hashedEmail); - - $this->emailEncryption->setUserConfirmationToken( - $this->getUserConfirmationToken() - ); - - $email = $this->emailEncryption->decryptEmailValue($hashedEmail); - - return $email; - } - - /** - * Set user class instance. - * - * @param UserInterface $user - * - * @return $this - */ - public function setUser(UserInterface $user) - { - $this->user = $user; - - return $this; - } - - /** - * Set new user email to be confirmed. Email value should be already - * validated. - * - * @param string $email - * - * @return $this - */ - public function setEmail($email) - { - $this->email = $email; - - $this->emailEncryption->setEmail($this->email); - - return $this; - } - - /** - * Set route to be used for confirmation ling generation. This route should - * contain path to confirmation action. - * - * @param string $confirmationRoute - * - * @return $this - */ - public function setConfirmationRoute($confirmationRoute) - { - $this->confirmationRoute = $confirmationRoute; - - return $this; - } - - /** - * Get token which indicates that email was confirmed. - * - * @return string - */ - public function getEmailConfirmedToken() - { - return base64_encode(self::EMAIL_CONFIRMED); - } - - /** - * Get or create new user confirmation token. - * - * @return string - */ - protected function getUserConfirmationToken() - { - // Generate new token if it's not set - if (!$this->user->getConfirmationToken()) { - $this->user->setConfirmationToken( - $this->tokenGenerator->generateToken() - ); - } - - return $this->user->getConfirmationToken(); - } -} diff --git a/Services/EmailConfirmation/Interfaces/EmailEncryptionInterface.php b/Services/EmailConfirmation/Interfaces/EmailEncryptionInterface.php deleted file mode 100644 index 0d7d8436cf..0000000000 --- a/Services/EmailConfirmation/Interfaces/EmailEncryptionInterface.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\Services\EmailConfirmation\Interfaces; - -/** - * Interface EmailEncryptionInterface. - */ -interface EmailEncryptionInterface -{ - /** - * @return string Encrypted email value - */ - public function encryptEmailValue(); - - /** - * @param string $encryptedEmail Encrypted email value - * - * @return string Decrypted email value - */ - public function decryptEmailValue($encryptedEmail); - - /** - * @param string $email Email to be encrypt/decrypt - * - * @return $this - */ - public function setEmail($email); - - /** - * @param string $userConfirmationToken - * - * @return $this - */ - public function setUserConfirmationToken($userConfirmationToken); -} diff --git a/Services/EmailConfirmation/Interfaces/EmailUpdateConfirmationInterface.php b/Services/EmailConfirmation/Interfaces/EmailUpdateConfirmationInterface.php deleted file mode 100644 index 61a0d7542b..0000000000 --- a/Services/EmailConfirmation/Interfaces/EmailUpdateConfirmationInterface.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\Services\EmailConfirmation\Interfaces; - -use FOS\UserBundle\Model\UserInterface; - -/** - * Interface EmailUpdateConfirmationInterface. - */ -interface EmailUpdateConfirmationInterface -{ - /** - * @param string $hashedEmail - * - * @return string - */ - public function fetchEncryptedEmailFromConfirmationLink($hashedEmail); - - /** - * @param UserInterface $user - * - * @return $this - */ - public function setUser(UserInterface $user); - - /** - * @param string $email - * - * @return $this - */ - public function setEmail($email); - - /** - * @param string $confirmationRoute - * - * @return $this - */ - public function setConfirmationRoute($confirmationRoute); -} diff --git a/Tests/DependencyInjection/FOSUserExtensionTest.php b/Tests/DependencyInjection/FOSUserExtensionTest.php index 8162f8cd92..a5c81e2db0 100644 --- a/Tests/DependencyInjection/FOSUserExtensionTest.php +++ b/Tests/DependencyInjection/FOSUserExtensionTest.php @@ -23,7 +23,7 @@ class FOSUserExtensionTest extends TestCase protected function tearDown() { - unset($this->configuration); + $this->configuration = null; } /** @@ -134,8 +134,6 @@ public function testDisableProfile() $config['profile'] = false; $loader->load(array($config), $this->configuration); $this->assertNotHasDefinition('fos_user.profile.form.factory'); - $this->assertNotHasDefinition('fos_user.email_update_confirmation.template'); - $this->assertNotHasDefinition('fos_user.email_update_confirmation.cypher_method'); } public function testDisableChangePassword() @@ -244,9 +242,6 @@ public function testUserLoadConfirmationEmailWithDefaults() $this->assertParameter(array('admin@acme.org' => 'Acme Corp'), 'fos_user.registration.confirmation.from_email'); $this->assertParameter('@FOSUser/Registration/email.txt.twig', 'fos_user.registration.confirmation.template'); $this->assertParameter('@FOSUser/Resetting/email.txt.twig', 'fos_user.resetting.email.template'); - $this->assertParameter('@FOSUser/Profile/email_update_confirmation.txt.twig', 'fos_user.email_update_confirmation.template'); - $this->assertNotHasDefinition('fos_user.email_update_confirmation.cypher_method'); - $this->assertNotHasDefinition('fos_user.email_update_confirmation.template'); $this->assertParameter(array('admin@acme.org' => 'Acme Corp'), 'fos_user.resetting.email.from_email'); $this->assertParameter(86400, 'fos_user.resetting.token_ttl'); } @@ -261,35 +256,6 @@ public function testUserLoadConfirmationEmail() $this->assertParameter('AcmeMyBundle:Resetting:mail.txt.twig', 'fos_user.resetting.email.template'); $this->assertParameter(array('reset@acme.org' => 'Acme Corp'), 'fos_user.resetting.email.from_email'); $this->assertParameter(7200, 'fos_user.resetting.retry_ttl'); - $this->assertParameter('@FOSUser/Profile/email_update_confirmation.txt.twig', 'fos_user.email_update_confirmation.template'); - $this->assertParameter(null, 'fos_user.email_update_confirmation.cypher_method'); - } - - public function testUserLoadConfirmationEmailAndUpdateConfirmation() - { - $this->configuration = new ContainerBuilder(); - $loader = new FOSUserExtension(); - $config = $this->getFullConfig(); - $loader->load(array($config), $this->configuration); - $this->assertTrue($this->configuration instanceof ContainerBuilder); - - $this->assertParameter(true, 'fos_user.registration.confirmation.enabled'); - $this->assertParameter(null, 'fos_user.email_update_confirmation.cypher_method'); - $this->assertParameter('@FOSUser/Profile/email_update_confirmation.txt.twig', 'fos_user.email_update_confirmation.template'); - } - - public function testUserLoadConfirmationEmailAndNotUpdateConfirmation() - { - $this->configuration = new ContainerBuilder(); - $loader = new FOSUserExtension(); - $config = $this->getFullConfig(); - $config['profile']['email_update_confirmation']['enabled'] = false; - $loader->load(array($config), $this->configuration); - $this->assertTrue($this->configuration instanceof ContainerBuilder); - - $this->assertParameter(true, 'fos_user.registration.confirmation.enabled'); - $this->assertNotHasDefinition('fos_user.email_update_confirmation.cypher_method'); - $this->assertNotHasDefinition('fos_user.email_update_confirmation.template'); } public function testUserLoadUtilServiceWithDefaults() @@ -424,8 +390,6 @@ protected function getFullConfig() type: acme_my_profile name: acme_profile_form validation_groups: [acme_profile] - email_update_confirmation: - enabled: true change_password: form: type: acme_my_change_password diff --git a/Tests/EventListener/FlashListenerTest.php b/Tests/EventListener/FlashListenerTest.php index e78676c5ba..a4237d4a81 100644 --- a/Tests/EventListener/FlashListenerTest.php +++ b/Tests/EventListener/FlashListenerTest.php @@ -45,9 +45,4 @@ public function testAddSuccessFlash() { $this->listener->addSuccessFlash($this->event, FOSUserEvents::CHANGE_PASSWORD_COMPLETED); } - - public function testAddInfoFlash() - { - $this->listener->addInfoFlash($this->event, FOSUserEvents::CHANGE_PASSWORD_COMPLETED); - } } diff --git a/Tests/Routing/RoutingTest.php b/Tests/Routing/RoutingTest.php index 624fede11d..df68fe8f5f 100644 --- a/Tests/Routing/RoutingTest.php +++ b/Tests/Routing/RoutingTest.php @@ -45,9 +45,6 @@ public function testLoadRouting($routeName, $path, array $methods) $subCollection->addPrefix('/resetting'); $collection->addCollection($subCollection); $collection->addCollection($loader->load(__DIR__.'/../../Resources/config/routing/security.xml')); - $subCollection = $loader->load(__DIR__.'/../../Resources/config/routing/update_email.xml'); - $subCollection->addPrefix('/profile'); - $collection->addCollection($subCollection); $route = $collection->get($routeName); $this->assertNotNull($route, sprintf('The route "%s" should exists', $routeName)); @@ -85,8 +82,6 @@ public function loadRoutingProvider() array('fos_user_security_login', '/login', array('GET', 'POST')), array('fos_user_security_check', '/login_check', array('POST')), array('fos_user_security_logout', '/logout', array('GET', 'POST')), - - array('fos_user_update_email_confirm', '/profile/confirm-email-update/{token}', array('GET')), ); } } diff --git a/Tests/Services/EmailEncryptionTest.php b/Tests/Services/EmailEncryptionTest.php deleted file mode 100644 index 7c7b878249..0000000000 --- a/Tests/Services/EmailEncryptionTest.php +++ /dev/null @@ -1,104 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\Tests\Util; - -use FOS\UserBundle\Services\EmailConfirmation\EmailEncryption; -use PHPUnit\Framework\TestCase; -use Symfony\Component\Validator\ConstraintViolationList; -use Symfony\Component\Validator\Validator\ValidatorInterface; - -class EmailEncryptionTest extends TestCase -{ - /** @var ValidatorInterface */ - private $emailValidator; - /** @var ConstraintViolationList */ - private $constraintViolationList; - - protected function setUp() - { - $this->emailValidator = $this->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')->disableOriginalConstructor()->getMock(); - $this->constraintViolationList = new ConstraintViolationList(array($this->getMockBuilder('Symfony\Component\Validator\ConstraintViolation')->disableOriginalConstructor()->getMock())); - } - - public function testEncryptDecryptEmail() - { - $this->emailValidator->expects($this->once())->method('validate')->will($this->returnValue($this->constraintViolationList)); - $this->constraintViolationList->remove(0); - $emailEncryption = new EmailEncryption($this->emailValidator); - $emailEncryption->setEmail('foo@example.com'); - $emailEncryption->setUserConfirmationToken('test_token'); - - $encryptedEmail = $emailEncryption->encryptEmailValue(); - $this->assertSame('foo@example.com', $emailEncryption->decryptEmailValue($encryptedEmail)); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testDecryptFromWrongEmailFormat() - { - $this->emailValidator->expects($this->once())->method('validate')->will($this->returnValue($this->constraintViolationList)); - $emailEncryption = new EmailEncryption($this->emailValidator); - $emailEncryption->setEmail('fooexample.com'); - $emailEncryption->setUserConfirmationToken('test_token'); - - $encryptedEmail = $emailEncryption->encryptEmailValue(); - $emailEncryption->decryptEmailValue($encryptedEmail); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testIntegerIsSetInsteadOfEmailString() - { - $emailEncryption = new EmailEncryption($this->emailValidator); - $emailEncryption->setEmail(123); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testIntegerIsSetInsteadOfConfirmationTokenString() - { - $emailEncryption = new EmailEncryption($this->emailValidator); - $emailEncryption->setUserConfirmationToken(123); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testNullIsSetInsteadOfConfirmationTokenString() - { - $emailEncryption = new EmailEncryption($this->emailValidator); - $emailEncryption->setUserConfirmationToken(null); - } - - public function testGetConfirmationToken() - { - $this->constraintViolationList->remove(0); - $emailEncryption = new EmailEncryption($this->emailValidator); - $emailEncryption->setUserConfirmationToken('test_token'); - - $confirmationToken = $emailEncryption->getConfirmationToken(); - $expectedConfirmationToken = pack('H*', hash('sha256', 'test_token')); - $this->assertSame($expectedConfirmationToken, $confirmationToken); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testGetConfirmationTokenIfUserConfirmationTokenIsNotSet() - { - $emailEncryption = new EmailEncryption($this->emailValidator); - $emailEncryption->getConfirmationToken(); - } -} diff --git a/Tests/Services/EmailUpdateConfirmationTest.php b/Tests/Services/EmailUpdateConfirmationTest.php deleted file mode 100644 index b3d0d3311f..0000000000 --- a/Tests/Services/EmailUpdateConfirmationTest.php +++ /dev/null @@ -1,88 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\Tests\Util; - -use FOS\UserBundle\Mailer\MailerInterface; -use FOS\UserBundle\Model\User; -use FOS\UserBundle\Services\EmailConfirmation\EmailEncryption; -use FOS\UserBundle\Services\EmailConfirmation\EmailUpdateConfirmation; -use FOS\UserBundle\Util\TokenGenerator; -use PHPUnit\Framework\TestCase; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; -use Symfony\Component\Routing\RouterInterface; -use Symfony\Component\Validator\ConstraintViolationList; -use Symfony\Component\Validator\Validator\ValidatorInterface; - -class EmailUpdateConfirmationTest extends TestCase -{ - /** @var ExpressionFunctionProviderInterface */ - private $provider; - /** @var RouterInterface */ - private $router; - /** @var TokenGenerator */ - private $tokenGenerator; - /** @var MailerInterface */ - private $mailer; - /** @var EmailEncryption */ - private $emailEncryption; - /** @var EventDispatcher */ - private $eventDispatcher; - /** @var EmailUpdateConfirmation */ - private $emailUpdateConfirmation; - /** @var User */ - private $user; - private $cypher_method = 'AES-128-CBC'; - - /** @var ValidatorInterface */ - private $emailValidator; - /** @var ConstraintViolationList */ - private $constraintViolationList; - - protected function setUp() - { - $this->emailValidator = $this->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')->disableOriginalConstructor()->getMock(); - $this->constraintViolationList = new ConstraintViolationList(array()); - $this->emailValidator->expects($this->once())->method('validate')->will($this->returnValue($this->constraintViolationList)); - - $this->provider = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface')->getMock(); - $this->user = $this->getMockBuilder('FOS\UserBundle\Model\User') - ->disableOriginalConstructor() - ->getMock(); - $this->router = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\Router') - ->disableOriginalConstructor() - ->getMock(); - - $this->tokenGenerator = $this->getMockBuilder('FOS\UserBundle\Util\TokenGenerator')->disableOriginalConstructor()->getMock(); - $this->mailer = $this->getMockBuilder('FOS\UserBundle\Mailer\TwigSwiftMailer')->disableOriginalConstructor()->getMock(); - $this->emailEncryption = new EmailEncryption($this->emailValidator, $this->cypher_method); - $this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); - - $this->emailUpdateConfirmation = new EmailUpdateConfirmation($this->router, $this->tokenGenerator, $this->mailer, $this->emailEncryption, $this->eventDispatcher); - $this->user->expects($this->any()) - ->method('getConfirmationToken') - ->will($this->returnValue('test_token')); - $this->emailUpdateConfirmation->setUser($this->user); - } - - public function testFetchEncryptedEmailFromConfirmationLinkMethod() - { - $emailEncryption = new EmailEncryption($this->emailValidator, $this->cypher_method); - $emailEncryption->setEmail('foo@example.com'); - $emailEncryption->setUserConfirmationToken('test_token'); - - $encryptedEmail = $emailEncryption->encryptEmailValue(); - - $email = $this->emailUpdateConfirmation->fetchEncryptedEmailFromConfirmationLink($encryptedEmail); - $this->assertSame('foo@example.com', $email); - } -} diff --git a/Upgrade.md b/Upgrade.md index 9627046c7c..efe479cd51 100644 --- a/Upgrade.md +++ b/Upgrade.md @@ -4,17 +4,6 @@ Upgrade instruction This document describes the changes needed when upgrading because of a BC break. For the full list of changes, please look at the Changelog file. -## 2.0.x => 2.1.0 - -### MailerInterface -For the implementation of [Confirmation of Changed Email](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/emails.rst#confirmation-of-changed-email)-feature, -the `FOSUserBundle/Mailer/MailerInterface` received a new method. - -`public function sendUpdateEmailConfirmation(UserInterface $user, $confirmationUrl, $toEmail);` - -If you use your own implementation of the `MailerInterface` and it does not inherit from one of the -implementations in `FOSUserBundle/Mailer`, then you will need to implement the new function as well. - ## 2.0.0-alpha3 to 2.0.0-beta1 Methods and properties removed from `FOS\UserBundle\Model\User`