diff --git a/examples/excel_examples/course-credential.xlsx b/examples/excel_examples/course-credential.xlsx index e2216a4..70b4516 100644 Binary files a/examples/excel_examples/course-credential.xlsx and b/examples/excel_examples/course-credential.xlsx differ diff --git a/examples/excel_examples/federation-membership.xlsx b/examples/excel_examples/federation-membership.xlsx index 3d20590..7aa9db8 100644 Binary files a/examples/excel_examples/federation-membership.xlsx and b/examples/excel_examples/federation-membership.xlsx differ diff --git a/idhub/models.py b/idhub/models.py index 2eae07f..7843d4c 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -704,7 +704,7 @@ class VerificableCredential(models.Model): cred_path = 'public/credentials' sid = self.hash - url_id = "https://{}/{}/{}".format( + url_id = "{}/{}/{}".format( domain, cred_path, sid diff --git a/idhub/static/images/4_Model_Certificat_html_941e7b967953b3f3.jpg b/idhub/static/images/4_Model_Certificat_html_941e7b967953b3f3.jpg new file mode 100644 index 0000000..12e9a3e Binary files /dev/null and b/idhub/static/images/4_Model_Certificat_html_941e7b967953b3f3.jpg differ diff --git a/idhub/templates/certificates/course-credential_ca.html b/idhub/templates/certificates/course-credential_ca.html new file mode 100644 index 0000000..e9a6912 --- /dev/null +++ b/idhub/templates/certificates/course-credential_ca.html @@ -0,0 +1,126 @@ +{% load i18n static %} + + + +Certificat + + + + + + + + + +
+
+
+ +
+
+
+
+ + LAFEDE.CAT – ORGANITZACIONS PER A LA JUSTÍCIA GLOBAL
CERTIFICA QUE:

+ {{ firstName }} {{ lastName }} amb DNI {{ personalIdentifier }}
+ Ha realitzat el curs {{ courseName }}, a {{ address|default:"" }} / de manera {{ modeOfInstruction }}, els dies {{ issued_date }}
+ La durada del curs ha estat de {{ courseDuration }} hores lectives corresponents a {{ courseDays }} sessions.
+
+
+
+
+
+ I per deixar-ne constància als efectes oportuns, signo el present certificat en data de {{ issued_date }} +
+
+ +
+
+ +
+
+ +
+
+ Pepa Martínez Peyrats
+ Directora
+ Lafede.cat - Federació d'Organitzacions per a la Justícia Global +
+
+ {% if qr %} +
+
+ +
+
+ {% endif %} +
+
+ Organitza: + Amb el suport de: + Amb la col·laboració de: +
+
+
+ +
+
+
+
+ + diff --git a/idhub/templates/certificates/course-credential_es.html b/idhub/templates/certificates/course-credential_es.html new file mode 100644 index 0000000..f97ec3b --- /dev/null +++ b/idhub/templates/certificates/course-credential_es.html @@ -0,0 +1,126 @@ +{% load i18n static %} + + + +Certificado + + + + + + + + + +
+
+
+ +
+
+
+
+ + LAFEDE.CAT – ORGANIZACIONES PARA LA JUSTÍCIA GLOBAL
CERTIFICA QUE:

+ {{ firstName }} {{ lastName }} con DNI {{ personalIdentifier }}
+ Ha realizado el curso {{ courseName }}, en {{ address }} / de manera {{ modeOfInstruction }}, los días {{ issued_date }}
+ La duración del curso ha sido de {{ courseDuration }} horas lectivas correspondientes a {{ courseDays }} sessiones.
+
+
+
+
+
+ Y para dejar constancia a los efectos oportunos, firmo el presente certificado en fecha de {{ issued_date }} +
+
+ +
+
+ +
+
+ +
+
+ Pepa Martínez Peyrats
+ Directora
+ Lafede.cat - Federación de Organizaciones por la Justícia Global +
+
+ {% if qr %} +
+
+ +
+
+ {% endif %} +
+
+ Organiza: + Con el soporte de: + Con la colaboración de: +
+
+
+ +
+
+
+
+ + diff --git a/idhub/templates/certificates/4_Model_Certificat.html b/idhub/templates/certificates/federation-membership_ca.html similarity index 77% rename from idhub/templates/certificates/4_Model_Certificat.html rename to idhub/templates/certificates/federation-membership_ca.html index ae29757..472db16 100644 --- a/idhub/templates/certificates/4_Model_Certificat.html +++ b/idhub/templates/certificates/federation-membership_ca.html @@ -2,7 +2,7 @@ -Certificado +Certificat @@ -73,12 +73,23 @@ +
+
+

A qui correspongui,

+

+ Pepa Martínez Peyrats, com a directora de Lafede.cat - Federació d'Organitzacions per a la Justícia Global, +

+
+
+
- LAFEDE.CAT – ORGANITZACIONS PER A LA JUSTÍCIA GLOBAL
CERTIFICA QUE:
- {{ first_name }} {{ last_name }} amb DNI {{ document_id }}
- Ha realitzat el curs {{ course }}, a {{ address }} / de manera virtual/presencial, els dies {{ date_course }}
- La durada del curs ha estat de {{ n_hours }} hores lectives corresponents a {{ n_lections }} sessions.
+ CERTIFICA
+


@@ -108,4 +119,4 @@ {% endif %}
- \ No newline at end of file + diff --git a/idhub/templates/certificates/federation-membership_es.html b/idhub/templates/certificates/federation-membership_es.html new file mode 100644 index 0000000..0550ac6 --- /dev/null +++ b/idhub/templates/certificates/federation-membership_es.html @@ -0,0 +1,122 @@ +{% load i18n static %} + + + +Certificado + + + + + + + + + +
+
+
+ +
+
+
+
+

A quién corresponda,

+

+ Pepa Martínez Peyrats, como directora de Lafede.cat - Federación de Organizaciones para la Justícia Global, +

+
+
+ +
+
+ CERTIFICA
+
    +
  • + Que la entidad {{ legalName }}, con NIF {{ taxReference }} y domicilio {{ streetAddress }} {{ postCode }} {{ city }} forma parte como entidad miembro de {{ federation }} (por el derecho/observadora) de Lafede.cat - Federación de Organizaciones para la Justícia Global, desde la Asamblea General Ordinaria celebrada el {{ issue_date }} +
  • +
+
+
+
+ Y para dejar constancia a los efectos oportunos, firmo el presente certificado en fecha de {{ issue_date }} +
+
+ +
+
+ +
+
+ +
+
+ Pepa Martínez Peyrats
+ Directora
+ Lafede.cat - Federació d'Organitzacions per a la Justícia Global +
+
+ {% if qr %} +
+
+ +
+
+ {% endif %} +
+ + diff --git a/idhub/templates/idhub/user/credential.html b/idhub/templates/idhub/user/credential.html index 9e1e0f4..6362a5e 100644 --- a/idhub/templates/idhub/user/credential.html +++ b/idhub/templates/idhub/user/credential.html @@ -9,19 +9,24 @@ {{ subtitle }}
-
- {% if object.get_status == 'Issued' %} -
- {% if object.eidas1_did and admin_validated %} - {% trans 'Download as PDF' %} - {% endif %} - {% trans 'Download as JSON' %} + {% if object.get_status == 'Issued' %} + {% if object.eidas1_did and admin_validated %} + + {% endif %} + {% endif %} +
+ {% if object.get_status == 'Issued' %} + {% if object.eidas1_did and admin_validated %} + {% endif %} + {% trans 'Download as JSON' %} + {% endif %} {% if object.get_status == 'Enabled' %} - {% endif %}
diff --git a/idhub/urls.py b/idhub/urls.py index cbcadcd..cae6aa6 100644 --- a/idhub/urls.py +++ b/idhub/urls.py @@ -73,7 +73,7 @@ urlpatterns = [ name='user_credentials'), path('user/credentials/', views_user.CredentialView.as_view(), name='user_credential'), - path('user/credentials//pdf', views_user.CredentialPdfView.as_view(), + path('user/credentials//pdf/', views_user.CredentialPdfView.as_view(), name='user_credential_pdf'), path('credentials//', views_user.CredentialJsonView.as_view(), name='user_credential_json'), diff --git a/idhub/user/views.py b/idhub/user/views.py index 6db3500..fb5dd63 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -209,14 +209,19 @@ class CredentialView(MyWallet, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + url_ca = reverse_lazy('idhub:user_credential_pdf', args=[self.object.id, 'ca']) + url_es = reverse_lazy('idhub:user_credential_pdf', args=[self.object.id, 'es']) context.update({ 'object': self.object, + 'url_ca': url_ca, + 'url_es': url_es, }) return context class CredentialPdfView(MyWallet, TemplateView): - template_name = "certificates/4_Model_Certificat.html" + template_name = "certificates/{}_{}.html" + template_name = "certificates/{}_{}.html" subtitle = _('Credential management') icon = 'bi bi-patch-check-fill' file_name = "certificate.pdf" @@ -225,6 +230,7 @@ class CredentialPdfView(MyWallet, TemplateView): if not cache.get("KEY_DIDS"): return redirect(reverse_lazy('idhub:user_dashboard')) pk = kwargs['pk'] + lang = kwargs.get('lang', 'ca') self.user = self.request.user self.object = get_object_or_404( VerificableCredential, @@ -232,6 +238,11 @@ class CredentialPdfView(MyWallet, TemplateView): eidas1_did__isnull=False, user=self.request.user ) + self.credential_type = self.object.schema.file_schema.split(".json")[0] + self.template_name = self.template_name.format( + self.credential_type, + lang + ) self.url_id = "{}://{}/public/credentials/{}".format( self.request.scheme, self.request.get_host(), @@ -247,49 +258,54 @@ class CredentialPdfView(MyWallet, TemplateView): response['Content-Disposition'] = 'attachment; filename={}'.format(self.file_name) return response - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - # this_folder = str(Path.cwd()) + def get_img_sign(self): path_img_sig = "idhub/static/images/4_Model_Certificat_html_58d7f7eeb828cf29.jpg" img_signature = next(Path.cwd().glob(path_img_sig)) with open(img_signature, 'rb') as _f: img_sig = base64.b64encode(_f.read()).decode('utf-8') + return img_sig - path_img_head = "idhub/static/images/4_Model_Certificat_html_7a0214c6fc8f2309.jpg" + def get_img_header(self): + path_img_head = "idhub/static/images/4_Model_Certificat_html_7a0214c6fc8f2309.jpg" img_header= next(Path.cwd().glob(path_img_head)) with open(img_header, 'rb') as _f: img_head = base64.b64encode(_f.read()).decode('utf-8') + return img_head + def get_img_footer(self): + path_img_foot = "idhub/static/images/4_Model_Certificat_html_941e7b967953b3f3.jpg" + img_foot= next(Path.cwd().glob(path_img_foot)) + with open(img_foot, 'rb') as _f: + img_foot = base64.b64encode(_f.read()).decode('utf-8') + return img_foot + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + img_sig = self.get_img_sign() + img_head = self.get_img_header() + img_foot = self.get_img_footer() qr = self.generate_qr_code(self.url_id) + issue_date_now = datetime.datetime.now() + issue_date = context.get('issuedDate', issue_date_now) - first_name = self.user.first_name and self.user.first_name.upper() or "" - last_name = self.user.first_name and self.user.last_name.upper() or "" - document_id = "0000000-L" - course = "COURSE 1" - address = "ADDRESS" - date_course = datetime.datetime.now() - n_hours = 40 - n_lections = 5 - issue_date = datetime.datetime.now() + context.update(dict(self.object.get_datas())) context.update({ 'object': self.object, "image_signature": img_sig, "image_header": img_head, - "first_name": first_name, - "last_name": last_name, - "document_id": document_id, - "course": course, - "address": address, - "date_course": date_course, - "n_hours": n_hours, - "n_lections": n_lections, - "issue_date": issue_date, - "qr": qr + "image_footer": img_foot, + "issue_date_now": issue_date_now.strftime("%d/%m/%Y"), + "issue_date": issue_date.strftime("%d/%m/%Y"), + "qr": qr, }) return context def build_certificate(self): - doc = self.render_to_response(context=self.get_context_data()) + try: + doc = self.render_to_response(context=self.get_context_data()) + except Exception: + self.template_name = "certificates/4_Model_Certificat_ca.html" + doc = self.render_to_response(context=self.get_context_data()) doc.render() pdf = weasyprint.HTML(string=doc.content) return pdf.write_pdf() @@ -340,7 +356,7 @@ class CredentialPdfView(MyWallet, TemplateView): w = IncrementalPdfFileWriter(_buffer) fields.append_signature_field( w, sig_field_spec=fields.SigFieldSpec( - 'Signature', box=(150, 100, 450, 150) + 'Signature', box=(150, 75, 450, 100) ) ) diff --git a/oidc4vp/models.py b/oidc4vp/models.py index 35085fd..e6a164a 100644 --- a/oidc4vp/models.py +++ b/oidc4vp/models.py @@ -319,3 +319,7 @@ class OAuth2VPToken(models.Model): "verifiableCredential", [{}] )[-1].get("credentialSubject") return json.dumps(self.user_info, indent=2) + + def get_user_info_all(self): + tk = json.loads(self.vp_token) + return json.dumps(tk, indent=2) diff --git a/oidc4vp/views.py b/oidc4vp/views.py index 851c652..0f60e94 100644 --- a/oidc4vp/views.py +++ b/oidc4vp/views.py @@ -219,7 +219,7 @@ class VerifyView(View): return email_message def get_verification(self): - return self.vp_token.get_user_info() + return self.vp_token.get_user_info_all() class AllowCodeView(View): def get(self, request, *args, **kwargs):