From 49e009b98202f71731648c1df8e5254af0a947d7 Mon Sep 17 00:00:00 2001 From: Bas Strooband Date: Mon, 28 Jan 2019 17:57:02 +0100 Subject: [PATCH] Create a pdf base template to support local url's In order to be able to view pdf's in production a template with only local urls' had to be created. --- app/Resources/views/pdf.html.twig | 58 ++++++++++++ app/config/config.yml | 1 + .../Controller/RegistrationController.php | 78 +++++++++------- .../partial/registrationEmailSent.html.twig | 90 ++++++++++++++++++ .../registrationEmailSent.html.twig | 92 +------------------ .../registrationEmailSentPdf.html.twig | 8 ++ 6 files changed, 204 insertions(+), 123 deletions(-) create mode 100644 app/Resources/views/pdf.html.twig create mode 100644 src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/partial/registrationEmailSent.html.twig create mode 100644 src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/registrationEmailSentPdf.html.twig diff --git a/app/Resources/views/pdf.html.twig b/app/Resources/views/pdf.html.twig new file mode 100644 index 000000000..9926a090f --- /dev/null +++ b/app/Resources/views/pdf.html.twig @@ -0,0 +1,58 @@ +{% extends 'MopaBootstrapBundle::base.html.twig' %} + +{% block title %} + {% if block('page_title') is not empty %}{{ block('page_title') }} — {% endif %} + {{ 'app.name'|trans }} +{% endblock title %} + +{% block head_style %} + + + +{% endblock head_style %} +{% block head_bottom %} +{% endblock head_bottom %} + +{% block navbar %} +{% endblock navbar %} + + {% block header %} + {% endblock header %} + + {% block page_header %} + + {% endblock page_header %} + + {% block content_row %} + {% block content %} + {% endblock content %} + {% endblock content_row %} + + {% block footer %} + {% endblock footer %} + +{% block foot_script %} + +{% endblock foot_script %} diff --git a/app/config/config.yml b/app/config/config.yml index 4d28fa1f7..992901f55 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -37,6 +37,7 @@ twig: exception_controller: SurfnetStepupSelfServiceSelfServiceBundle:Exception:show globals: global_view_parameters: "@self_service.service.global_view_parameters" + root_path: "%kernel.root_dir%" # Assetic Configuration assetic: diff --git a/src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RegistrationController.php b/src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RegistrationController.php index 2071f388e..5617201a3 100644 --- a/src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RegistrationController.php +++ b/src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RegistrationController.php @@ -129,36 +129,7 @@ public function verifyEmailAction(Request $request) */ public function registrationEmailSentAction($secondFactorId) { - $identity = $this->getIdentity(); - - /** @var \Surfnet\StepupMiddlewareClientBundle\Identity\Dto\VerifiedSecondFactor $secondFactor */ - $secondFactor = $this->get('surfnet_stepup_self_service_self_service.service.second_factor') - ->findOneVerified($secondFactorId); - - $parameters = [ - 'email' => $identity->email, - 'secondFactorId' => $secondFactor->id, - 'registrationCode' => $secondFactor->registrationCode, - 'expirationDate' => $secondFactor->registrationRequestedAt->add( - new DateInterval('P14D') - ), - 'locale' => $identity->preferredLocale, - 'verifyEmail' => $this->emailVerificationIsRequired(), - ]; - - $raService = $this->get('self_service.service.ra'); - $raLocationService = $this->get('self_service.service.ra_location'); - - $institutionConfigurationOptions = $this->get('self_service.service.institution_configuration_options') - ->getInstitutionConfigurationOptionsFor($identity->institution); - - if ($institutionConfigurationOptions->useRaLocations) { - $parameters['raLocations'] = $raLocationService->listRaLocationsFor($identity->institution); - } elseif (!$institutionConfigurationOptions->showRaaContactInformation) { - $parameters['ras'] = $raService->listRasWithoutRaas($identity->institution); - } else { - $parameters['ras'] = $raService->listRas($identity->institution); - } + $parameters = $this->buildRegistrationActionParameters($secondFactorId); return $this->render( 'SurfnetStepupSelfServiceSelfServiceBundle:Registration:registrationEmailSent.html.twig', @@ -172,8 +143,14 @@ public function registrationEmailSentAction($secondFactorId) */ public function registrationPdfAction($secondFactorId) { - $content = $this->registrationEmailSentAction($secondFactorId) - ->getContent(); + $parameters = $this->buildRegistrationActionParameters($secondFactorId); + + $response = $this->render( + 'SurfnetStepupSelfServiceSelfServiceBundle:Registration:registrationEmailSentPdf.html.twig', + $parameters + ); + $content = $response->getContent(); + $mpdf = new Mpdf( array( @@ -202,4 +179,41 @@ public function registrationPdfAction($secondFactorId) return $response; } + + + private function buildRegistrationActionParameters($secondFactorId) + { + $identity = $this->getIdentity(); + + /** @var \Surfnet\StepupMiddlewareClientBundle\Identity\Dto\VerifiedSecondFactor $secondFactor */ + $secondFactor = $this->get('surfnet_stepup_self_service_self_service.service.second_factor') + ->findOneVerified($secondFactorId); + + $parameters = [ + 'email' => $identity->email, + 'secondFactorId' => $secondFactor->id, + 'registrationCode' => $secondFactor->registrationCode, + 'expirationDate' => $secondFactor->registrationRequestedAt->add( + new DateInterval('P14D') + ), + 'locale' => $identity->preferredLocale, + 'verifyEmail' => $this->emailVerificationIsRequired(), + ]; + + $raService = $this->get('self_service.service.ra'); + $raLocationService = $this->get('self_service.service.ra_location'); + + $institutionConfigurationOptions = $this->get('self_service.service.institution_configuration_options') + ->getInstitutionConfigurationOptionsFor($identity->institution); + + if ($institutionConfigurationOptions->useRaLocations) { + $parameters['raLocations'] = $raLocationService->listRaLocationsFor($identity->institution); + } elseif (!$institutionConfigurationOptions->showRaaContactInformation) { + $parameters['ras'] = $raService->listRasWithoutRaas($identity->institution); + } else { + $parameters['ras'] = $raService->listRas($identity->institution); + } + + return $parameters; + } } diff --git a/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/partial/registrationEmailSent.html.twig b/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/partial/registrationEmailSent.html.twig new file mode 100644 index 000000000..803896459 --- /dev/null +++ b/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/partial/registrationEmailSent.html.twig @@ -0,0 +1,90 @@ +

{{ 'ss.registration.registration_email_sent.text.thank_you_for_registration'|trans }}

+ +

{{ 'ss.registration.registration_email_sent.text.activation_instructions'|trans }}

+ + + +
+ +

+ {{ 'ss.registration.registration_email_sent.label.expiration_date' + |trans({'%expirationDate%': expirationDate|localizeddate('full', 'none', locale)}) }} +

+ +
+
+ + + + + + + +
{{ 'ss.registration.registration_email_sent.label.registration_code'|trans }}{{ registrationCode }}
+
+
+ +
+ +

{{ 'ss.registration.registration_email_sent.text.registration_code_has_been_sent'|trans({'%email%': email}) }}

+ +
+ {% if not verifyEmail %} +

{{ 'ss.registration.registration_email_sent.text.registration_code_has_been_sent_no_email'|trans }}

+ {% endif %} + +
+ + + + {{ 'ss.registration.registration_email_sent.text.registration_code_has_been_sent_print'|trans }} + + + + {{ 'ss.registration.registration_email_sent.text.registration_code_has_been_sent_pdf'|trans }} + +
+ +
+ +{% if raLocations is defined %} +

{{ 'ss.registration.registration_email_sent.title.list_of_ra_locations'|trans }}

+ + {% if raLocations.elements is empty %} +

{{ 'ss.registration.registration_email_sent.text.no_ra_locations_for_your_institution'|trans }}

+ {% else %} + + {% endif %} +{% else %} +

{{ 'ss.registration.registration_email_sent.title.list_of_ras'|trans }}

+ + {% if ras.elements is empty %} +

{{ 'ss.registration.registration_email_sent.text.no_ras_for_your_institution'|trans }}

+ {% else %} + + {% endif %} +{% endif %} diff --git a/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/registrationEmailSent.html.twig b/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/registrationEmailSent.html.twig index 3f5a7ca4b..2a3931860 100644 --- a/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/registrationEmailSent.html.twig +++ b/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/registrationEmailSent.html.twig @@ -14,97 +14,7 @@ {% block content %}

{{ block('page_title') }}

- -

{{ 'ss.registration.registration_email_sent.text.thank_you_for_registration'|trans }}

- -

{{ 'ss.registration.registration_email_sent.text.activation_instructions'|trans }}

- - - -
- -

- {{ 'ss.registration.registration_email_sent.label.expiration_date' - |trans({'%expirationDate%': expirationDate|localizeddate('full', 'none', locale)}) }} -

- -
-
- - - - - - - -
{{ 'ss.registration.registration_email_sent.label.registration_code'|trans }}{{ registrationCode }}
-
-
- -
- -

{{ 'ss.registration.registration_email_sent.text.registration_code_has_been_sent'|trans({'%email%': email}) }}

- -
- {% if not verifyEmail %} -

{{ 'ss.registration.registration_email_sent.text.registration_code_has_been_sent_no_email'|trans }}

- {% endif %} - -
- - - - {{ 'ss.registration.registration_email_sent.text.registration_code_has_been_sent_print'|trans }} - - - - {{ 'ss.registration.registration_email_sent.text.registration_code_has_been_sent_pdf'|trans }} - -
- -
- - {% if raLocations is defined %} -

{{ 'ss.registration.registration_email_sent.title.list_of_ra_locations'|trans }}

- - {% if raLocations.elements is empty %} -

{{ 'ss.registration.registration_email_sent.text.no_ra_locations_for_your_institution'|trans }}

- {% else %} - - {% endif %} - {% else %} -

{{ 'ss.registration.registration_email_sent.title.list_of_ras'|trans }}

- - {% if ras.elements is empty %} -

{{ 'ss.registration.registration_email_sent.text.no_ras_for_your_institution'|trans }}

- {% else %} - - {% endif %} - {% endif %} + {% include 'SurfnetStepupSelfServiceSelfServiceBundle:Registration/partial:registrationEmailSent.html.twig' %} {% endblock %} {% block body_end %} diff --git a/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/registrationEmailSentPdf.html.twig b/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/registrationEmailSentPdf.html.twig new file mode 100644 index 000000000..6235f1578 --- /dev/null +++ b/src/Surfnet/StepupSelfService/SelfServiceBundle/Resources/views/Registration/registrationEmailSentPdf.html.twig @@ -0,0 +1,8 @@ +{% extends "::pdf.html.twig" %} + +{% block page_title %}{{ 'ss.registration.registration_email_sent.title'|trans }}{% endblock %} + +{% block content %} +

{{ block('page_title') }}

+ {% include 'SurfnetStepupSelfServiceSelfServiceBundle:Registration/partial:registrationEmailSent.html.twig' %} +{% endblock %}