From a59ddf3223d475987cdc1e707b633f6cadf40820 Mon Sep 17 00:00:00 2001 From: Camille Simiand <camille.simiand@tetras-libre.fr> Date: Fri, 25 Feb 2022 16:01:15 +0100 Subject: [PATCH] Refacto + umap email field --- src/Controller/CapsuleEditorController.php | 6 ++-- src/Controller/RegistrationController.php | 4 +-- src/Controller/ResetPasswordController.php | 4 +-- src/Controller/UserController.php | 30 +++++++++++++++---- src/Form/EditUserProfileFormType.php | 12 ++++++-- .../capsule/editors/list_editors.html.twig | 4 +-- .../capsule/groups/capsule_groups.html.twig | 4 +-- .../capsule/groups/user_groups.html.twig | 4 +-- templates/capsule/index.html.twig | 4 +-- templates/legacy/legacy.html.twig | 7 ----- templates/registration/register.html.twig | 6 ++-- templates/user/edit_email_address.html.twig | 21 +++++++++++++ templates/user/profile.html.twig | 10 +++++-- translations/messages.en.yaml | 6 +++- translations/messages.fr.yaml | 5 +++- 15 files changed, 92 insertions(+), 35 deletions(-) create mode 100644 templates/user/edit_email_address.html.twig diff --git a/src/Controller/CapsuleEditorController.php b/src/Controller/CapsuleEditorController.php index 6b08bbc..0cc7c3d 100755 --- a/src/Controller/CapsuleEditorController.php +++ b/src/Controller/CapsuleEditorController.php @@ -278,9 +278,6 @@ class CapsuleEditorController extends AbstractController int $capsule_id, Request $request ): Response { - $form = $this->createForm(RemoveEditorFormType::class); - $form->handleRequest($request); - $capsule = $this->capsule_repository->findOneBy(['id' => $capsule_id]); if (! $capsule instanceof Capsule) { throw new \Exception('The retrieved capsule is not an instance of Capsule.'); @@ -289,6 +286,9 @@ class CapsuleEditorController extends AbstractController $pending_editor_invitation = $this->capsule_pending_editor_invitation_repository ->findOneBy(['id' => $pending_editor_invitation_id]); + $form = $this->createForm(RemoveEditorFormType::class); + $form->handleRequest($request); + if (! $pending_editor_invitation instanceof PendingEditorInvitation) { $this->addFlash( 'warning', diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index 4155bb7..e641063 100755 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -69,7 +69,7 @@ class RegistrationController extends AbstractController } return $this->renderForm('registration/register.html.twig', [ - 'registrationForm' => $form, + 'registrationForm' => $form ]); } @@ -92,7 +92,7 @@ class RegistrationController extends AbstractController try { $this->email_verifier->handleEmailConfirmation($request, $user); } catch (VerifyEmailExceptionInterface $exception) { - $this->addFlash('verify_email_error', $exception->getReason()); + $this->addFlash('error', $exception->getReason()); return $this->redirectToRoute('app_register'); } diff --git a/src/Controller/ResetPasswordController.php b/src/Controller/ResetPasswordController.php index 7169714..a58c51a 100755 --- a/src/Controller/ResetPasswordController.php +++ b/src/Controller/ResetPasswordController.php @@ -43,7 +43,7 @@ class ResetPasswordController extends AbstractController } return $this->renderForm('reset_password/request.html.twig', [ - 'requestForm' => $form, + 'requestForm' => $form ]); } @@ -118,7 +118,7 @@ class ResetPasswordController extends AbstractController } return $this->renderForm('reset_password/reset.html.twig', [ - 'resetForm' => $form, + 'resetForm' => $form ]); } diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 52c454c..91b811c 100755 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -44,18 +44,38 @@ class UserController extends AbstractController return $this->redirectToRoute('app_logout'); } - $form = $this->createForm(EditUserProfileFormType::class, $current_user); - - $form->setData($current_user); + $form = $this->createForm( + EditUserProfileFormType::class, + $current_user, + ['current_email_address' => $current_user->getEmail()] + ); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->entity_manager->persist($current_user); $this->entity_manager->flush(); + $current_user->setFirstName($form->get('firstName')->getData()); + $current_user->setLastName($form->get('lastName')->getData()); + $this->entity_manager->persist($current_user); + $this->entity_manager->flush(); + + $new_email_address = $form->get('email')->getData(); + if ($current_user->getEmail() !== $new_email_address) { + $this->addFlash( + 'warning', + $this->translator->trans('user.profile.updated.warning', [ + 'new_email_address' => $new_email_address + ]) + ); + + return $this->render('user/edit_email_address.html.twig', [ + 'new_email_address' => $form->get('email')->getData() + ]); + } $this->addFlash( - 'profile_updated_success', - $this->translator->trans('user.profile.updated_success') + 'success', + $this->translator->trans('user.profile.updated.success') ); return $this->redirectToRoute('show_profile'); diff --git a/src/Form/EditUserProfileFormType.php b/src/Form/EditUserProfileFormType.php index 637d12b..a78a51e 100755 --- a/src/Form/EditUserProfileFormType.php +++ b/src/Form/EditUserProfileFormType.php @@ -12,6 +12,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints as Assert; class EditUserProfileFormType extends AbstractType { @@ -40,9 +41,14 @@ class EditUserProfileFormType extends AbstractType 'email', EmailType::class, [ - 'constraints' => [new NotBlank(['message' => 'email.not_blank'])], + 'data' => $options['current_email_address'], + 'constraints' => [ + new NotBlank(['message' => 'email.not_blank']), + new Assert\Email() + ], 'label' => 'general.email', - 'empty_data' => '' + 'empty_data' => '', + 'mapped' => false, ] ) ->add( @@ -70,6 +76,8 @@ class EditUserProfileFormType extends AbstractType { $resolver->setDefaults([ 'data_class' => User::class, + 'current_email_address' => '' ]); +// $resolver->setAllowedTypes('current_email_address', 'string'); } } diff --git a/templates/capsule/editors/list_editors.html.twig b/templates/capsule/editors/list_editors.html.twig index 4a04b89..0b71139 100644 --- a/templates/capsule/editors/list_editors.html.twig +++ b/templates/capsule/editors/list_editors.html.twig @@ -18,13 +18,13 @@ </div> {% for flashWarning in app.flashes('warning') %} - <div class="text-center alert alert-warning col-5 mx-auto my-5 mt-2" role="alert"> + <div class="text-center alert alert-warning col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5 mt-2" role="alert"> {{ flashWarning }} </div> {% endfor %} {% for flashSuccess in app.flashes('success') %} - <div class="text-center alert alert-success col-5 mx-auto my-5 mt-2" role="alert"> + <div class="text-center alert alert-success col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5 mt-2" role="alert"> {{ flashSuccess }} </div> {% endfor %} diff --git a/templates/capsule/groups/capsule_groups.html.twig b/templates/capsule/groups/capsule_groups.html.twig index 5129485..ad38080 100644 --- a/templates/capsule/groups/capsule_groups.html.twig +++ b/templates/capsule/groups/capsule_groups.html.twig @@ -18,13 +18,13 @@ </div> {% for flashWarning in app.flashes('warning') %} - <div class="text-center alert alert-warning col-5 mx-auto my-5 mt-2" role="alert"> + <div class="text-center alert alert-warning col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5 mt-2" role="alert"> {{ flashWarning }} </div> {% endfor %} {% for flashSuccess in app.flashes('success') %} - <div class="text-center alert alert-success col-5 mx-auto my-5 mt-2" role="alert"> + <div class="text-center alert alert-success col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5 mt-2" role="alert"> {{ flashSuccess }} </div> {% endfor %} diff --git a/templates/capsule/groups/user_groups.html.twig b/templates/capsule/groups/user_groups.html.twig index d0737cc..808b416 100644 --- a/templates/capsule/groups/user_groups.html.twig +++ b/templates/capsule/groups/user_groups.html.twig @@ -17,13 +17,13 @@ </div> {% for flashWarning in app.flashes('warning') %} - <div class="text-center alert alert-warning col-5 mx-auto my-5 mt-2" role="alert"> + <div class="text-center alert alert-warning col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5 mt-2" role="alert"> {{ flashWarning }} </div> {% endfor %} {% for flashSuccess in app.flashes('success') %} - <div class="text-center alert alert-success col-5 mx-auto my-5 mt-2" role="alert"> + <div class="text-center alert alert-success col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5 mt-2" role="alert"> {{ flashSuccess }} </div> {% endfor %} diff --git a/templates/capsule/index.html.twig b/templates/capsule/index.html.twig index 5c47a37..59b64db 100644 --- a/templates/capsule/index.html.twig +++ b/templates/capsule/index.html.twig @@ -34,13 +34,13 @@ </div> {% for flashWarning in app.flashes('warning') %} - <div class="text-center alert alert-warning col-5 mx-auto my-5" role="alert"> + <div class="text-center alert alert-warning col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5" role="alert"> {{ flashWarning }} </div> {% endfor %} {% for flashSuccess in app.flashes('success') %} - <div class="text-center alert alert-success col-5 mx-auto my-5" role="alert"> + <div class="text-center alert alert-success col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5" role="alert"> {{ flashSuccess }} </div> {% endfor %} diff --git a/templates/legacy/legacy.html.twig b/templates/legacy/legacy.html.twig index 2bf7dbf..8d4d49e 100644 --- a/templates/legacy/legacy.html.twig +++ b/templates/legacy/legacy.html.twig @@ -1,21 +1,14 @@ {% extends 'layout.html.twig' %} - - {% block body %} <iframe src="{{ url }}" style="width:100%;height:100%;top:0;left:0;position:absolute" - {# width="1200" - height="600" #} - frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen> </iframe> - - {% endblock %} diff --git a/templates/registration/register.html.twig b/templates/registration/register.html.twig index 3f9b4c0..99d5864 100644 --- a/templates/registration/register.html.twig +++ b/templates/registration/register.html.twig @@ -6,8 +6,10 @@ {% block body %} <div class="mt-4"> - {% for flashError in app.flashes('verify_email_error') %} - <div class="alert alert-danger col-6 mx-auto my-5 h1" role="alert">{{ flashError }}</div> + {% for flashError in app.flashes('error') %} + <div class="alert alert-danger col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5 h1" role="alert"> + {{ flashError }} + </div> {% endfor %} {{ form_start(registrationForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-column justify-content-center'}}) }} diff --git a/templates/user/edit_email_address.html.twig b/templates/user/edit_email_address.html.twig new file mode 100644 index 0000000..a3017af --- /dev/null +++ b/templates/user/edit_email_address.html.twig @@ -0,0 +1,21 @@ +{% extends 'layout.html.twig' %} + +{% block title %} + {{ 'user.edit_email_address'|trans }} +{% endblock %} + +{% block body %} + <div class="row gx-0"> + <div class="row-title-box"> + <h3 class="row-title"> + {{ 'user.edit_email_address'|trans }} + </h3> + </div> + </div> + + {% for flashWarning in app.flashes('warning') %} + <div class="text-center alert alert-warning col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5" role="alert"> + {{ flashWarning }} + </div> + {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/templates/user/profile.html.twig b/templates/user/profile.html.twig index a02eef8..5747fed 100644 --- a/templates/user/profile.html.twig +++ b/templates/user/profile.html.twig @@ -13,12 +13,18 @@ </div> </div> - {% for flashSuccess in app.flashes('profile_updated_success') %} - <div class="text-center alert alert-success col-5 mx-auto my-5" role="alert"> + {% for flashSuccess in app.flashes('success') %} + <div class="text-center alert alert-success col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5" role="alert"> {{ flashSuccess }} </div> {% endfor %} + {% for flashWarning in app.flashes('warning') %} + <div class="text-center alert alert-warning col-11 col-md-10 col-lg-9 col-xl-8 mx-auto my-5" role="alert"> + {{ flashWarning }} + </div> + {% endfor %} + <div class="d-flex flex-column flex-md-row justify-content-center align-items-center"> <div class="profile-block d-flex flex-row ps-3 ps-md-5 pe-3 pe-md-5 pt-4 pb-3 fw-normal me-0 me-md-5"> <div class="pe-3 pe-md-4 text-nowrap"> diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 9b2e68d..012af5a 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -107,7 +107,10 @@ user: title: My profile edit: Edit profile update: Update - updated_success: The profile has been updated + updated: + success: The profile has been updated + warning: In order to update your current email address related to your Memorekall account with the new email address new_email_address, + please confirm this change following the link your received by email. password: edit: Edit password current: Current password @@ -115,6 +118,7 @@ user: updated_success: The password has been updated edit_profile: Edit my profile edit_password: Edit my password + edit_email_address: Edit my email address editors: title: Editors diff --git a/translations/messages.fr.yaml b/translations/messages.fr.yaml index 55f20ce..b2e4e26 100644 --- a/translations/messages.fr.yaml +++ b/translations/messages.fr.yaml @@ -106,7 +106,9 @@ user: title: Mon profil edit: Modifier mon profil update: Mettre à jour - updated_success: Votre profil a bien été mis à jour + updated: + success: Votre profil a bien été mis à jour + warning: Veuillez confirmer le changement d'adresse e-mail en activant le lien que vous avez reçu par mail à l'adresse new_email_address. L'adresse e-amil reliée à votre compte Memorekall sera alors mise à jour avec la nouvelle new_email_address. password: edit: Modifier mon mot de passe current: Mot de passe actuel @@ -114,6 +116,7 @@ user: updated_success: Votre mot de passe a bien été modifié edit_profile: Modifier mon mot de passe edit_password: Modifier mon mot de passe + edit_email_address: Modifier mon adresse e-mail editors: title: Editeurs d'une capsule -- GitLab