user credentials view
This commit is contained in:
parent
33f51fcdbc
commit
ef476773ac
|
@ -0,0 +1,5 @@
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
|
||||||
|
class ImportForm(forms.Form):
|
||||||
|
file_import = forms.FileField()
|
|
@ -20,6 +20,7 @@ from apiregiter import iota
|
||||||
from idhub_auth.models import User
|
from idhub_auth.models import User
|
||||||
from idhub.mixins import AdminView
|
from idhub.mixins import AdminView
|
||||||
from idhub.email.views import NotifyActivateUserByEmail
|
from idhub.email.views import NotifyActivateUserByEmail
|
||||||
|
from idhub.admin.forms import ImportForm
|
||||||
from idhub.models import (
|
from idhub.models import (
|
||||||
DID,
|
DID,
|
||||||
File_datas,
|
File_datas,
|
||||||
|
@ -28,7 +29,7 @@ from idhub.models import (
|
||||||
Service,
|
Service,
|
||||||
Schemas,
|
Schemas,
|
||||||
UserRol,
|
UserRol,
|
||||||
VerifiableCredential,
|
VerificableCredential,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -406,7 +407,7 @@ class AdminCredentialsView(Credentials):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context.update({
|
context.update({
|
||||||
'credentials': VerifiableCredential.objects,
|
'credentials': VerificableCredential.objects,
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -763,7 +764,7 @@ class AdminImportStep3View(ImportExport):
|
||||||
def create_credential(self, user, row):
|
def create_credential(self, user, row):
|
||||||
d = copy.copy(self.json_schema)
|
d = copy.copy(self.json_schema)
|
||||||
d['instance'] = row
|
d['instance'] = row
|
||||||
return VerifiableCredential.objects.create(
|
return VerificableCredential.objects.create(
|
||||||
verified=False,
|
verified=False,
|
||||||
user=user,
|
user=user,
|
||||||
data=json.dumps(d)
|
data=json.dumps(d)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.5 on 2023-10-26 13:46
|
# Generated by Django 4.2.5 on 2023-10-27 09:32
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -96,7 +96,7 @@ class Migration(migrations.Migration):
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='VerifiableCredential',
|
name='VerificableCredential',
|
||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
'id',
|
'id',
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Schemas(models.Model):
|
||||||
return self.get_schema.get('description', '')
|
return self.get_schema.get('description', '')
|
||||||
|
|
||||||
|
|
||||||
class VerifiableCredential(models.Model):
|
class VerificableCredential(models.Model):
|
||||||
"""
|
"""
|
||||||
Definition of Verificable Credentials
|
Definition of Verificable Credentials
|
||||||
"""
|
"""
|
||||||
|
@ -90,6 +90,11 @@ class VerifiableCredential(models.Model):
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
return self.Status(self.status).label
|
return self.Status(self.status).label
|
||||||
|
|
||||||
|
def get_datas(self):
|
||||||
|
data = json.loads(self.data).get('instance').items()
|
||||||
|
return data
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
|
||||||
class VCTemplate(models.Model):
|
class VCTemplate(models.Model):
|
||||||
wkit_template_id = models.CharField(max_length=250)
|
wkit_template_id = models.CharField(max_length=250)
|
||||||
data = models.TextField()
|
data = models.TextField()
|
||||||
|
|
|
@ -144,10 +144,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3>
|
|
||||||
<i class="{{ icon }}"></i>
|
|
||||||
{{ subtitle }}
|
|
||||||
</h3>
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
{% extends "idhub/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-3">
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
{% for k, v in object.get_datas %}
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-3 text-end">
|
||||||
|
<strong>{{ k|capfirst }}:</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col bg-light text-secondary">
|
||||||
|
{{ v }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-3 text-end">
|
||||||
|
<strong>Date of Issue:</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col bg-light text-secondary">
|
||||||
|
{{ object.issuer_on|default_if_none:"" }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-3 text-end">
|
||||||
|
<strong>Status:</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col bg-light text-secondary">
|
||||||
|
{{ object.get_status}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col text-center">
|
||||||
|
<a class="btn btn-green-user" href="{% url 'idhub:user_credential_json' object.id %}">{% trans 'View in JSON format' %}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -2,4 +2,40 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% 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 'Issue' %}</button></th>
|
||||||
|
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Status' %}</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.issue_on }}</td>
|
||||||
|
<td>{{ f.get_status }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{% url 'idhub:user_credential' f.id %}" class="text-primary">
|
||||||
|
<i class="bi bi-eye"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,4 +2,8 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,4 +2,8 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped table-sm">
|
<table class="table table-striped table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
{% load django_bootstrap5 %}
|
{% load django_bootstrap5 %}
|
||||||
<form role="form" method="post">
|
<form role="form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
<div class="row mt-5">
|
<div class="row mt-5">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
|
|
|
@ -2,4 +2,8 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,6 +2,18 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col text-center">
|
||||||
|
<a href="javascript:void()" type="button" class="btn btn-green-user me-3">{% trans 'ARCO Forms' %}</a>
|
||||||
|
<a href="javascript:void()" type="button" class="btn btn-green-user">{% trans 'Notice of Privacy' %}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% load django_bootstrap5 %}
|
{% load django_bootstrap5 %}
|
||||||
<form role="form" method="post">
|
<form role="form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -25,4 +37,36 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-sm text-center">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Membership' %}</button></th>
|
||||||
|
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'From' %}</button></th>
|
||||||
|
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'To' %}</button></th>
|
||||||
|
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Credentials' %}</button></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for membership in object.memberships.all %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ membership.get_type }}</td>
|
||||||
|
<td>{{ membership.start_date|default:'' }}</td>
|
||||||
|
<td>{{ membership.end_date|default:'' }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="javascript:void()" class="text-primary">
|
||||||
|
<i class="bi bi-eye"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h3>
|
||||||
|
<i class="{{ icon }}"></i>
|
||||||
|
{{ subtitle }}
|
||||||
|
</h3>
|
||||||
<div class="row mt-5">
|
<div class="row mt-5">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
|
|
|
@ -77,6 +77,10 @@ urlpatterns = [
|
||||||
name='user_dids_del'),
|
name='user_dids_del'),
|
||||||
path('user/credentials/', views_user.UserCredentialsView.as_view(),
|
path('user/credentials/', views_user.UserCredentialsView.as_view(),
|
||||||
name='user_credentials'),
|
name='user_credentials'),
|
||||||
|
path('user/credentials/<int:pk>', views_user.UserCredentialView.as_view(),
|
||||||
|
name='user_credential'),
|
||||||
|
path('user/credentials/<int:pk>/json', views_user.UserCredentialJsonView.as_view(),
|
||||||
|
name='user_credential_json'),
|
||||||
path('user/credentials_required/',
|
path('user/credentials_required/',
|
||||||
views_user.UserCredentialsRequiredView.as_view(),
|
views_user.UserCredentialsRequiredView.as_view(),
|
||||||
name='user_credentials_required'),
|
name='user_credentials_required'),
|
||||||
|
|
|
@ -5,11 +5,12 @@ from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
from django.http import HttpResponse
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from apiregiter import iota
|
from apiregiter import iota
|
||||||
from idhub.user.forms import ProfileForm
|
from idhub.user.forms import ProfileForm
|
||||||
from idhub.mixins import UserView
|
from idhub.mixins import UserView
|
||||||
from idhub.models import DID
|
from idhub.models import DID, VerificableCredential
|
||||||
|
|
||||||
|
|
||||||
class MyProfile(UserView):
|
class MyProfile(UserView):
|
||||||
|
@ -59,12 +60,62 @@ class UserCredentialsView(MyWallet, TemplateView):
|
||||||
subtitle = _('Credentials')
|
subtitle = _('Credentials')
|
||||||
icon = 'bi bi-patch-check-fill'
|
icon = 'bi bi-patch-check-fill'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context.update({
|
||||||
|
'credentials': VerificableCredential.objects,
|
||||||
|
})
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class UserCredentialView(MyWallet, TemplateView):
|
||||||
|
template_name = "idhub/user/credential.html"
|
||||||
|
subtitle = _('Credential')
|
||||||
|
icon = 'bi bi-patch-check-fill'
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
self.pk = kwargs['pk']
|
||||||
|
self.object = get_object_or_404(
|
||||||
|
VerificableCredential,
|
||||||
|
pk=self.pk,
|
||||||
|
user=self.request.user
|
||||||
|
)
|
||||||
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context.update({
|
||||||
|
'object': self.object,
|
||||||
|
})
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class UserCredentialJsonView(MyWallet, TemplateView):
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
pk = kwargs['pk']
|
||||||
|
self.object = get_object_or_404(
|
||||||
|
VerificableCredential,
|
||||||
|
pk=pk,
|
||||||
|
user=self.request.user
|
||||||
|
)
|
||||||
|
response = HttpResponse(self.object.data, content_type="application/json")
|
||||||
|
response['Content-Disposition'] = 'attachment; filename={}'.format("credential.json")
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
class UserCredentialsRequiredView(MyWallet, TemplateView):
|
class UserCredentialsRequiredView(MyWallet, TemplateView):
|
||||||
template_name = "idhub/user/credentials_required.html"
|
template_name = "idhub/user/credentials_required.html"
|
||||||
subtitle = _('Credentials required')
|
subtitle = _('Credentials required')
|
||||||
icon = 'bi bi-patch-check-fill'
|
icon = 'bi bi-patch-check-fill'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context.update({
|
||||||
|
'credentials': VerificableCredential.objects,
|
||||||
|
})
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
class UserCredentialsPresentationView(MyWallet, TemplateView):
|
class UserCredentialsPresentationView(MyWallet, TemplateView):
|
||||||
template_name = "idhub/user/credentials_presentation.html"
|
template_name = "idhub/user/credentials_presentation.html"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.5 on 2023-10-26 13:46
|
# Generated by Django 4.2.5 on 2023-10-27 09:32
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,9 @@ def create_admin_users(email, password):
|
||||||
|
|
||||||
|
|
||||||
def create_users(email, password):
|
def create_users(email, password):
|
||||||
User.objects.create(email=email, password=password)
|
u= User.objects.create(email=email, password=password)
|
||||||
|
u.set_password(password)
|
||||||
|
u.save()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in New Issue