request credential
This commit is contained in:
parent
ef476773ac
commit
2ca1663e90
|
@ -54,9 +54,10 @@ class VerificableCredential(models.Model):
|
|||
"""
|
||||
class Status(models.IntegerChoices):
|
||||
ENABLE = 1, _("Enable")
|
||||
ISSUED = 2, _("Issued")
|
||||
REVOKED = 3, _("Revoked")
|
||||
EXPIRED = 4, _("Expired")
|
||||
REQUIRED = 2, _("Required")
|
||||
ISSUED = 3, _("Issued")
|
||||
REVOKED = 4, _("Revoked")
|
||||
EXPIRED = 5, _("Expired")
|
||||
|
||||
id_string = models.CharField(max_length=250)
|
||||
verified = models.BooleanField()
|
||||
|
|
|
@ -110,8 +110,8 @@
|
|||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if path == 'user_credentials_required' %}active2{% endif %}" href="{% url 'idhub:user_credentials_required' %}">
|
||||
Credentials required
|
||||
<a class="nav-link {% if path == 'user_credentials_request' %}active2{% endif %}" href="{% url 'idhub:user_credentials_request' %}">
|
||||
Credentials request
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
|
|
|
@ -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 %}
|
|
@ -1,9 +0,0 @@
|
|||
{% extends "idhub/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
{% endblock %}
|
|
@ -81,9 +81,12 @@ urlpatterns = [
|
|||
name='user_credential'),
|
||||
path('user/credentials/<int:pk>/json', views_user.UserCredentialJsonView.as_view(),
|
||||
name='user_credential_json'),
|
||||
path('user/credentials_required/',
|
||||
views_user.UserCredentialsRequiredView.as_view(),
|
||||
name='user_credentials_required'),
|
||||
path('user/credentials/request/',
|
||||
views_user.UserCredentialsRequestView.as_view(),
|
||||
name='user_credentials_request'),
|
||||
path('user/credentials/<int:pk>/request/',
|
||||
views_user.UserCredentialRequestView.as_view(),
|
||||
name='user_credential_request'),
|
||||
path('user/credentials_presentation/',
|
||||
views_user.UserCredentialsPresentationView.as_view(),
|
||||
name='user_credentials_presentation'),
|
||||
|
|
|
@ -104,19 +104,43 @@ class UserCredentialJsonView(MyWallet, TemplateView):
|
|||
return response
|
||||
|
||||
|
||||
class UserCredentialsRequiredView(MyWallet, TemplateView):
|
||||
template_name = "idhub/user/credentials_required.html"
|
||||
subtitle = _('Credentials required')
|
||||
class UserCredentialsRequestView(MyWallet, TemplateView):
|
||||
template_name = "idhub/user/credentials_request.html"
|
||||
subtitle = _('Credentials request')
|
||||
icon = 'bi bi-patch-check-fill'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
creds = VerificableCredential.objects.filter(
|
||||
user=self.request.user,
|
||||
status=VerificableCredential.Status.ENABLE
|
||||
)
|
||||
context.update({
|
||||
'credentials': VerificableCredential.objects,
|
||||
'credentials': creds,
|
||||
})
|
||||
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):
|
||||
template_name = "idhub/user/credentials_presentation.html"
|
||||
subtitle = _('Credentials Presentation')
|
||||
|
|
Loading…
Reference in New Issue