request credential

This commit is contained in:
Cayo Puigdefabregas 2023-10-30 18:29:21 +01:00
parent ef476773ac
commit 2ca1663e90
6 changed files with 79 additions and 21 deletions

View File

@ -54,9 +54,10 @@ class VerificableCredential(models.Model):
""" """
class Status(models.IntegerChoices): class Status(models.IntegerChoices):
ENABLE = 1, _("Enable") ENABLE = 1, _("Enable")
ISSUED = 2, _("Issued") REQUIRED = 2, _("Required")
REVOKED = 3, _("Revoked") ISSUED = 3, _("Issued")
EXPIRED = 4, _("Expired") REVOKED = 4, _("Revoked")
EXPIRED = 5, _("Expired")
id_string = models.CharField(max_length=250) id_string = models.CharField(max_length=250)
verified = models.BooleanField() verified = models.BooleanField()

View File

@ -110,8 +110,8 @@
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {% if path == 'user_credentials_required' %}active2{% endif %}" href="{% url 'idhub:user_credentials_required' %}"> <a class="nav-link {% if path == 'user_credentials_request' %}active2{% endif %}" href="{% url 'idhub:user_credentials_request' %}">
Credentials required Credentials request
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">

View File

@ -0,0 +1,39 @@
{% extends "idhub/base.html" %}
{% load i18n %}
{% block content %}
<h3>
<i class="{{ icon }}"></i>
{{ subtitle }}
</h3>
<div class="row mt-5">
<div class="col">
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Type' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Details' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Enabled' %}</button></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{% for f in credentials.all %}
<tr style="font-size:15px;">
<td>{{ f.type }}</td>
<td>{{ f.description }}</td>
<td>{{ f.created_on }}</td>
<td>
<a href="{% url 'idhub:user_credential_request' f.id %}" class="btn btn-green-user">
{% trans 'Request' %}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock %}

View File

@ -1,9 +0,0 @@
{% extends "idhub/base.html" %}
{% load i18n %}
{% block content %}
<h3>
<i class="{{ icon }}"></i>
{{ subtitle }}
</h3>
{% endblock %}

View File

@ -81,9 +81,12 @@ urlpatterns = [
name='user_credential'), name='user_credential'),
path('user/credentials/<int:pk>/json', views_user.UserCredentialJsonView.as_view(), path('user/credentials/<int:pk>/json', views_user.UserCredentialJsonView.as_view(),
name='user_credential_json'), name='user_credential_json'),
path('user/credentials_required/', path('user/credentials/request/',
views_user.UserCredentialsRequiredView.as_view(), views_user.UserCredentialsRequestView.as_view(),
name='user_credentials_required'), name='user_credentials_request'),
path('user/credentials/<int:pk>/request/',
views_user.UserCredentialRequestView.as_view(),
name='user_credential_request'),
path('user/credentials_presentation/', path('user/credentials_presentation/',
views_user.UserCredentialsPresentationView.as_view(), views_user.UserCredentialsPresentationView.as_view(),
name='user_credentials_presentation'), name='user_credentials_presentation'),

View File

@ -104,19 +104,43 @@ class UserCredentialJsonView(MyWallet, TemplateView):
return response return response
class UserCredentialsRequiredView(MyWallet, TemplateView): class UserCredentialsRequestView(MyWallet, TemplateView):
template_name = "idhub/user/credentials_required.html" template_name = "idhub/user/credentials_request.html"
subtitle = _('Credentials required') subtitle = _('Credentials request')
icon = 'bi bi-patch-check-fill' icon = 'bi bi-patch-check-fill'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
creds = VerificableCredential.objects.filter(
user=self.request.user,
status=VerificableCredential.Status.ENABLE
)
context.update({ context.update({
'credentials': VerificableCredential.objects, 'credentials': creds,
}) })
return context return context
class UserCredentialRequestView(MyWallet, TemplateView):
success_url = reverse_lazy('idhub:user_credentials_request')
def get(self, request, *args, **kwargs):
pk = kwargs['pk']
creds = VerificableCredential.objects.filter(
pk=pk,
user=self.request.user,
status=VerificableCredential.Status.ENABLE
)
if not creds:
messages.error(self.request, _("Not exists the credential!"))
else:
cred = creds[0]
cred.status = VerificableCredential.Status.REQUIRED
cred.save()
messages.success(self.request, _("The credential was required successfully!"))
return redirect(self.success_url)
class UserCredentialsPresentationView(MyWallet, TemplateView): class UserCredentialsPresentationView(MyWallet, TemplateView):
template_name = "idhub/user/credentials_presentation.html" template_name = "idhub/user/credentials_presentation.html"
subtitle = _('Credentials Presentation') subtitle = _('Credentials Presentation')