From ad8775a3cf57ba29445bfdd88ae2a15d2303fbb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20G=C3=B3mez=20Benavides?= Date: Mon, 27 Mar 2023 07:49:09 -0600 Subject: [PATCH 1/4] Breaking for app. In web, logs to stdout (easy to see in docker desktop). Register in web and app can be the same? --- app/config/config_dev.yml | 7 +++ app/config/services.yml | 10 ++- docker-compose.yml | 2 +- src/Action/Register.php | 63 ++++++++++++++++--- .../Registration/register_content.html.twig | 2 +- 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml index 44ef828039..54c37e228c 100755 --- a/app/config/config_dev.yml +++ b/app/config/config_dev.yml @@ -79,6 +79,13 @@ monolog: level: info max_files: 3 channels: [dabba] + register: + type: stream + path: "php://stdout" + level: debug + include_stacktraces: true + channels: [register] + # channels: [register] # uncomment to get logging in your browser # you may have to allow bigger header sizes in your Web server configuration #firephp: diff --git a/app/config/services.yml b/app/config/services.yml index 8646ee0522..24592ffeda 100755 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -86,7 +86,7 @@ services: League\Flysystem\Filesystem $taskImportsFilesystem: '@task_imports_filesystem' League\Flysystem\Filesystem $receiptsFilesystem: '@receipts_filesystem' Nucleos\UserBundle\Util\CanonicalizerInterface: '@nucleos_user.util.canonicalizer.default' - + Spatie\GuzzleRateLimiterMiddleware\Store: '@AppBundle\Geocoder\RateLimiterStore' # Autowiring variables in controllers @@ -212,6 +212,8 @@ services: coopcycle.user_provider: class: AppBundle\Security\NucleosUserBundleUserProvider arguments: ['@nucleos_user.user_manager', { facebook: facebookId }] + tags: + - { name: monolog.logger, channel: register } AppBundle\EventListener\MaintenanceListener: arguments: @@ -581,6 +583,8 @@ services: - '@coopcycle.user_manager.inner' - '@nucleos_user.object_manager' class: AppBundle\Security\UserManager + tags: + - { name: monolog.logger, channel: register } AppBundle\Service\SettingsManager: arguments: @@ -697,6 +701,8 @@ services: arguments: $confirmationEnabled: '%nucleos_profile.registration.confirmation.enabled%' $mailer: '@nucleos_profile.mailer.default' + tags: + - { name: monolog.logger, channel: register } AppBundle\Action\ResettingSendEmail: public: true @@ -1025,6 +1031,8 @@ services: $orderRepository: '@sylius.repository.order' $customerRepository: '@sylius.repository.customer' $secret: '%secret%' + tags: + - { name: monolog.logger, channel: register } AppBundle\Embed\Context: ~ diff --git a/docker-compose.yml b/docker-compose.yml index b7764306df..bf6986e8cd 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -168,7 +168,7 @@ services: /usr/bin/mc mb --region $S3_REGION --ignore-existing coopcycle/images/restaurants/; /usr/bin/mc mb --region $S3_REGION --ignore-existing coopcycle/images/stores/; /usr/bin/mc mb --region $S3_REGION --ignore-existing coopcycle/images/tasks/; - /usr/bin/mc policy set public coopcycle/images/; + /usr/bin/mc anonymous set public coopcycle/images/; " tile38: diff --git a/src/Action/Register.php b/src/Action/Register.php index 014e815e26..61756d4a1b 100644 --- a/src/Action/Register.php +++ b/src/Action/Register.php @@ -21,6 +21,23 @@ use Symfony\Component\Validator\ConstraintViolationInterface; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Validator\ValidatorInterface; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; +use Monolog\Logger; +use Monolog\Handler\StreamHandler; + +use Nucleos\ProfileBundle\Event\GetResponseRegistrationEvent; +use Nucleos\ProfileBundle\Event\UserFormEvent; +use Nucleos\ProfileBundle\Form\Model\Registration; +use Nucleos\ProfileBundle\Form\Type\RegistrationFormType; +use Nucleos\ProfileBundle\NucleosProfileEvents; +use Nucleos\UserBundle\Event\FilterUserResponseEvent; +use Nucleos\UserBundle\Event\FormEvent; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\RouterInterface; +use Twig\Environment; class Register { @@ -31,6 +48,10 @@ class Register private $tokenGenerator; private $mailer; private $confirmationEnabled; + /** + * @var Environment + */ + private $twig; public function __construct( UserManagerInterface $userManager, @@ -40,7 +61,10 @@ public function __construct( TokenGeneratorInterface $tokenGenerator, MailerInterface $mailer, ValidatorInterface $validator, - bool $confirmationEnabled) + bool $confirmationEnabled, + LoggerInterface $registerLogger, + Environment $twig, + ) { $this->userManager = $userManager; $this->jwtManager = $jwtManager; @@ -50,6 +74,8 @@ public function __construct( $this->mailer = $mailer; $this->validator = $validator; $this->confirmationEnabled = $confirmationEnabled; + $this->registerLogger = $registerLogger; + $this->twig = $twig; } /** @@ -61,14 +87,31 @@ public function __construct( */ public function registerAction(Request $request) { + // create a log channel + $log = new Logger('nameregisterAction'); + $log->pushHandler(new StreamHandler('php://stdout', Logger::WARNING)); // <<< uses a stream + + // add records to the log + $log->warning('Foo registerAction'); + $log->error('Bar registerAction'); $email = $request->request->get('_email'); $username = $request->request->get('_username'); $password = $request->request->get('_password'); + $password_confirmation = $request->request->get('_password_confirmation'); $telephone = $request->request->get('_telephone'); $givenName = $request->request->get('_givenName'); $familyName = $request->request->get('_familyName'); $fullName = $request->request->get('_fullName'); - + $this->registerLogger->info('Request data : email={email}; username={username}; password={password}; password_confirmation={password_confirmation}; telephone={telephone}; givenName={givenName}; familyName={familyName}; fullName={fullName};', [ + 'email' => $email, + 'username' => $username, + 'password' => $password, + 'password_confirmation' => $password_confirmation, + 'telephone' => $telephone, + 'givenName' => $givenName, + 'familyName' => $familyName, + 'fullName' => $fullName + ]); $data = [ 'email' => $email, 'username' => $username, @@ -94,8 +137,8 @@ public function registerAction(Request $request) $violations->add($cause); } } - - throw new ValidationException($violations); + return new RedirectResponse('/register'); + //throw new ValidationException($violations); } $registration = $form->getData(); @@ -103,9 +146,12 @@ public function registerAction(Request $request) $user = $registration->toUser($this->userManager); $violations = $this->validator->validate($user); - + $this->registerLogger->info('violations data : violations={violations};', [ + 'violations' => $violations + ]); if (count($violations) > 0) { - throw new ValidationException($violations); + return new RedirectResponse('/register'); + //throw new ValidationException($violations); } $user->setEnabled($this->confirmationEnabled ? false : true); @@ -129,6 +175,9 @@ public function registerAction(Request $request) $this->dispatcher->dispatch($event, Events::AUTHENTICATION_SUCCESS); $response->setData($event->getData()); - return $response; + return new Response($this->twig->render('@NucleosProfile/Registration/register.html.twig', [ + 'form' => $form->createView(), + ])); + //return $response; } } diff --git a/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig b/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig index b4fa67fe59..e3f0ec04b8 100644 --- a/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig +++ b/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig @@ -10,7 +10,7 @@
- {{ form_start(form, {'method': 'post', 'action': path('nucleos_profile_registration_register'), 'attr': {'class': 'nucleos_profile_registration_register'}}) }} + {{ form_start(form, {'method': 'post', 'action': path('api_register'), 'attr': {'class': 'api_register'}}) }} {{ form_row(form.email) }} {{ form_row(form.username) }} {{ form_row(form.plainPassword) }} From 5f8dc7f08168b475bd6948047ee0aa2dcbade77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20G=C3=B3mez=20Benavides?= Date: Mon, 3 Apr 2023 19:10:40 -0600 Subject: [PATCH 2/4] Reverted API break --- src/Action/Register.php | 11 +++-------- .../Registration/register_content.html.twig | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Action/Register.php b/src/Action/Register.php index 61756d4a1b..508f6afb03 100644 --- a/src/Action/Register.php +++ b/src/Action/Register.php @@ -137,8 +137,7 @@ public function registerAction(Request $request) $violations->add($cause); } } - return new RedirectResponse('/register'); - //throw new ValidationException($violations); + throw new ValidationException($violations); } $registration = $form->getData(); @@ -150,8 +149,7 @@ public function registerAction(Request $request) 'violations' => $violations ]); if (count($violations) > 0) { - return new RedirectResponse('/register'); - //throw new ValidationException($violations); + throw new ValidationException($violations); } $user->setEnabled($this->confirmationEnabled ? false : true); @@ -175,9 +173,6 @@ public function registerAction(Request $request) $this->dispatcher->dispatch($event, Events::AUTHENTICATION_SUCCESS); $response->setData($event->getData()); - return new Response($this->twig->render('@NucleosProfile/Registration/register.html.twig', [ - 'form' => $form->createView(), - ])); - //return $response; + return $response; } } diff --git a/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig b/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig index e3f0ec04b8..b4fa67fe59 100644 --- a/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig +++ b/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig @@ -10,7 +10,7 @@
- {{ form_start(form, {'method': 'post', 'action': path('api_register'), 'attr': {'class': 'api_register'}}) }} + {{ form_start(form, {'method': 'post', 'action': path('nucleos_profile_registration_register'), 'attr': {'class': 'nucleos_profile_registration_register'}}) }} {{ form_row(form.email) }} {{ form_row(form.username) }} {{ form_row(form.plainPassword) }} From 65711595fe5be50e5e4eb069a86fbb8f056606a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20G=C3=B3mez=20Benavides?= Date: Wed, 5 Apr 2023 19:00:52 -0600 Subject: [PATCH 3/4] Validation messages in web register --- .../Registration/register_content.html.twig | 45 ++++++++++++++++++- translations/messages.en.yml | 1 + translations/messages.es.yml | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig b/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig index b4fa67fe59..26f6d9f9df 100644 --- a/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig +++ b/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig @@ -1,4 +1,4 @@ -{% form_theme form 'bootstrap_3_layout.html.twig' %} +{#% form_theme form 'bootstrap_3_layout.html.twig' %#} {% trans_default_domain 'NucleosProfileBundle' %} @@ -10,10 +10,39 @@
+ {{ dump(form.vars.errors) }} {{ form_start(form, {'method': 'post', 'action': path('nucleos_profile_registration_register'), 'attr': {'class': 'nucleos_profile_registration_register'}}) }} {{ form_row(form.email) }} {{ form_row(form.username) }} + {% set break = false %} + {% for key, error in form.vars.errors if not break %} + {% if error.cause.propertyPath == 'username' %} +
+
    +
  • + + {{ error.message }} +
  • +
+
+ {% set break = true %} + {% endif %} + {% endfor %} {{ form_row(form.plainPassword) }} + {% set break = false %} + {% for key, error in form.vars.errors if not break %} + {% if error.cause.propertyPath == 'plainPassword' %} +
+
    +
  • + + {{ error.message }} +
  • +
+
+ {% set break = true %} + {% endif %} + {% endfor %} {% if form.legal is defined %} {{ form_row(form.legal) }} @@ -31,6 +60,20 @@
{% trans from 'messages' %}authentication.unsubscribe{% endtrans %}
+ {% set break = false %} + {% for key, error in form.vars.errors if not break %} + {% if error.cause.propertyPath == 'email' %} +
+
    +
  • + + {% trans from 'messages' %}authentication.registration_error{% endtrans %} +
  • +
+
+ {% set break = true %} + {% endif %} + {% endfor %} {{ form_end(form) }}
diff --git a/translations/messages.en.yml b/translations/messages.en.yml index 8e8c01a198..0e12c1fd69 100644 --- a/translations/messages.en.yml +++ b/translations/messages.en.yml @@ -868,6 +868,7 @@ authentication.forgot_password: Forgot password? authentication.not_registered_yet: Not registered yet? authentication.create_account: Create your account authentication.already_registered: Already registered? +authentication.registration_error: There is a problem with the information you provided. Please review it and try again. authentication.unsubscribe: You can easily unsubscribe at any time via the unsubscribe links in each of our emails authentication.sign_in: Sign in authentication.choose_password: Choose your password diff --git a/translations/messages.es.yml b/translations/messages.es.yml index 2342dc279c..2e6990d5a1 100644 --- a/translations/messages.es.yml +++ b/translations/messages.es.yml @@ -583,6 +583,7 @@ authentication.forgot_password: ¿Contraseña olvidada? authentication.not_registered_yet: ¿Todavía no estas registrado? authentication.create_account: Crea tu cuenta authentication.already_registered: ¿Ya tienes una cuenta? +authentication.registration_error: Hay un problema con tu registro. Revisa tus datos e intenta de nuevo por favor. authentication.sign_in: Regístrate maintenance.text: Sitio en mantenimiento. Volveremos pronto api_apps.breadcrumb: Clientes API From d6b00ea4003593dbc54a0dedb4b9fcfe869cad96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20G=C3=B3mez=20Benavides?= Date: Thu, 13 Apr 2023 01:20:15 -0600 Subject: [PATCH 4/4] =?UTF-8?q?Olvid=C3=A9=20quitar=20el=20dump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NucleosProfileBundle/Registration/register_content.html.twig | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig b/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig index 26f6d9f9df..cebf6ea243 100644 --- a/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig +++ b/templates/bundles/NucleosProfileBundle/Registration/register_content.html.twig @@ -10,7 +10,6 @@

- {{ dump(form.vars.errors) }} {{ form_start(form, {'method': 'post', 'action': path('nucleos_profile_registration_register'), 'attr': {'class': 'nucleos_profile_registration_register'}}) }} {{ form_row(form.email) }} {{ form_row(form.username) }}