From c2e76d83ab1e23f73f0994864842d3919a4b20e2 Mon Sep 17 00:00:00 2001
From: Sebastien Curt <curt.sebastien@gmail.com>
Date: Wed, 24 Nov 2021 00:45:08 +0100
Subject: [PATCH] Add page mail sent on post registration

---
 config/packages/dev/web_profiler.yaml         |  2 +-
 config/packages/framework.yaml                |  1 +
 config/packages/twig.yaml                     |  1 +
 src/Controller/RegistrationController.php     | 25 +++++++++++++++--
 templates/registration.base.html.twig         | 28 +++++++++++++++++++
 templates/registration/register.html.twig     | 14 ++++------
 .../registration/register_mail_sent.html.twig | 10 +++++++
 7 files changed, 69 insertions(+), 12 deletions(-)
 create mode 100644 templates/registration.base.html.twig
 create mode 100644 templates/registration/register_mail_sent.html.twig

diff --git a/config/packages/dev/web_profiler.yaml b/config/packages/dev/web_profiler.yaml
index e92166a..fd22424 100644
--- a/config/packages/dev/web_profiler.yaml
+++ b/config/packages/dev/web_profiler.yaml
@@ -1,6 +1,6 @@
 web_profiler:
     toolbar: true
-    intercept_redirects: false
+    intercept_redirects: true
 
 framework:
     profiler: { only_exceptions: false }
diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml
index 7853e9e..07b9ab3 100644
--- a/config/packages/framework.yaml
+++ b/config/packages/framework.yaml
@@ -11,6 +11,7 @@ framework:
         cookie_secure: auto
         cookie_samesite: lax
         storage_factory_id: session.storage.factory.native
+        enabled: true
 
     #esi: true
     #fragments: true
diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml
index f9f4cc5..3be7d52 100644
--- a/config/packages/twig.yaml
+++ b/config/packages/twig.yaml
@@ -1,5 +1,6 @@
 twig:
     default_path: '%kernel.project_dir%/templates'
+    form_themes: ['bootstrap_5_layout.html.twig']
 
 when@test:
     twig:
diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php
index 76e4571..f349e7a 100644
--- a/src/Controller/RegistrationController.php
+++ b/src/Controller/RegistrationController.php
@@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Bridge\Twig\Mime\TemplatedEmail;
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\RequestStack;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Mime\Address;
 use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
@@ -19,10 +20,12 @@ use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
 class RegistrationController extends AbstractController
 {
     private EmailVerifier $emailVerifier;
+    private RequestStack  $requestStack;
 
-    public function __construct(EmailVerifier $emailVerifier)
+    public function __construct(EmailVerifier $emailVerifier, RequestStack $requestStack)
     {
         $this->emailVerifier = $emailVerifier;
+        $this->requestStack = $requestStack;
     }
 
     /**
@@ -57,9 +60,13 @@ class RegistrationController extends AbstractController
                     ->subject('Please Confirm your Email')
                     ->htmlTemplate('registration/confirmation_email.html.twig')
             );
-            // do anything else you need here, like send an email
 
-            return $this->redirectToRoute('_profiler_home');
+            // do anything else you need here, like send an email
+            // return $this->redirectToRoute('app_login');
+            $this->requestStack->getSession()->set('userid', $user->getId());
+            return $this->redirectToRoute('app_register_mail_sent');
+//            $message = 'An email has been sent to '. $user->getEmail() .'. It contains an activation link you must click to activate your account.';
+//            $this->addFlash('success', $message);
         }
 
         return $this->render('registration/register.html.twig', [
@@ -98,4 +105,16 @@ class RegistrationController extends AbstractController
 
         return $this->redirectToRoute('app_register');
     }
+
+    /**
+     * @Route("/register_mail_sent", name="app_register_mail_sent")
+     */
+    public function mailSentMessage(UserRepository $userRepository){
+        $userid = $this->requestStack->getSession()->get('userid');
+        $user = $userRepository->find($userid);
+
+        return $this->render('registration/register_mail_sent.html.twig', [
+            'user' =>  $user,
+        ]);
+    }
 }
diff --git a/templates/registration.base.html.twig b/templates/registration.base.html.twig
new file mode 100644
index 0000000..dbefa8d
--- /dev/null
+++ b/templates/registration.base.html.twig
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>{% block title %}MemoRekall{% endblock %}</title>
+  {# Run `composer require symfony/webpack-encore-bundle`
+           and uncomment the following Encore helpers to start using Symfony UX #}
+  {% block stylesheets %}
+    {{ encore_entry_link_tags('app') }}
+  {% endblock %}
+
+  {% block javascripts %}
+    {{ encore_entry_script_tags('app') }}
+  {% endblock %}
+</head>
+<body class="container">
+<div class="d-flex flex-row justify-content-center mb-5">
+  <div class="d-flex flex-column">
+    <a href="/my_capsules"><img id="header-memorekall-logo" class="memorekall-logo" src="{{ asset('build/images/MemoRekall.png') }}"></a>
+    <div class="d-flex flex-row justify-content-center">
+      <a href="/login" class="btn btn-primary m-2 px-4 py-3" >LOG IN</a>
+      <a href="/register" class="btn btn-primary m-2 px-4 py-3" >SIGN IN</a>
+    </div>
+  </div>
+</div>
+{% block body %}{% endblock %}
+</body>
+</html>
\ No newline at end of file
diff --git a/templates/registration/register.html.twig b/templates/registration/register.html.twig
index 7ea0360..c2d1417 100644
--- a/templates/registration/register.html.twig
+++ b/templates/registration/register.html.twig
@@ -1,23 +1,21 @@
-{% extends 'base.html.twig' %}
+{% extends 'registration.base.html.twig' %}
 
 {% block title %}Register{% endblock %}
 {% block body %}
-  <div class="container d-flex flex-column justify-content-center">
+  <div class="d-flex flex-column justify-content-center">
     {% for flashError in app.flashes('verify_email_error') %}
-      <div class="alert alert-danger" role="alert">{{ flashError }}</div>
+      <div class="alert alert-danger col-6 mx-auto my-5 h1" role="alert">{{ flashError }}</div>
     {% endfor %}
-    {% for flashError in app.flashes('success') %}
-      <div class="alert alert-danger" role="alert">{{ flashError }}</div>
+    {% for flashMessage in app.flashes('success') %}
+      <div class="alert alert-warning col-6 mx-auto my-5 h1" role="alert" >{{ flashMessage }}</div>
     {% endfor %}
-
     <div>
 
     </div>
 
 
     {{ form_start(registrationForm, {'attr': {'class': 'd-flex flex-column justify-content-center'}}) }}
-    {{ form_errors(registrationForm) }}
-    {{ form_row(registrationForm.firstName) }}
+    {{ form_row(registrationForm.firstName)  }}
     {{ form_row(registrationForm.lastName) }}
     {{ form_row(registrationForm.email) }}
     {{ form_row(registrationForm.plainPassword, {
diff --git a/templates/registration/register_mail_sent.html.twig b/templates/registration/register_mail_sent.html.twig
new file mode 100644
index 0000000..4acd445
--- /dev/null
+++ b/templates/registration/register_mail_sent.html.twig
@@ -0,0 +1,10 @@
+{% extends 'registration.base.html.twig' %}
+{% block title %}Mail registration sent{% endblock %}
+
+{% block body %}
+  <div class="container d-flex flex-row justify-content-center">
+    <div class="col-6">
+      <p class="alert">An email has been sent to {{ user.getEmail() }} . It contains an activation link you must click to activate your account</p>
+    </div>
+  </div>
+{% endblock %}
\ No newline at end of file
-- 
GitLab