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.mixins import AdminView
|
||||
from idhub.email.views import NotifyActivateUserByEmail
|
||||
from idhub.admin.forms import ImportForm
|
||||
from idhub.models import (
|
||||
DID,
|
||||
File_datas,
|
||||
|
@ -28,7 +29,7 @@ from idhub.models import (
|
|||
Service,
|
||||
Schemas,
|
||||
UserRol,
|
||||
VerifiableCredential,
|
||||
VerificableCredential,
|
||||
)
|
||||
|
||||
|
||||
|
@ -406,7 +407,7 @@ class AdminCredentialsView(Credentials):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update({
|
||||
'credentials': VerifiableCredential.objects,
|
||||
'credentials': VerificableCredential.objects,
|
||||
})
|
||||
return context
|
||||
|
||||
|
@ -763,7 +764,7 @@ class AdminImportStep3View(ImportExport):
|
|||
def create_credential(self, user, row):
|
||||
d = copy.copy(self.json_schema)
|
||||
d['instance'] = row
|
||||
return VerifiableCredential.objects.create(
|
||||
return VerificableCredential.objects.create(
|
||||
verified=False,
|
||||
user=user,
|
||||
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.db import migrations, models
|
||||
|
@ -96,7 +96,7 @@ class Migration(migrations.Migration):
|
|||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='VerifiableCredential',
|
||||
name='VerificableCredential',
|
||||
fields=[
|
||||
(
|
||||
'id',
|
||||
|
|
|
@ -48,7 +48,7 @@ class Schemas(models.Model):
|
|||
return self.get_schema.get('description', '')
|
||||
|
||||
|
||||
class VerifiableCredential(models.Model):
|
||||
class VerificableCredential(models.Model):
|
||||
"""
|
||||
Definition of Verificable Credentials
|
||||
"""
|
||||
|
@ -90,6 +90,11 @@ class VerifiableCredential(models.Model):
|
|||
def get_status(self):
|
||||
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):
|
||||
wkit_template_id = models.CharField(max_length=250)
|
||||
data = models.TextField()
|
||||
|
|
|
@ -144,10 +144,6 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
{% block 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 %}
|
||||
|
||||
{% 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 %}
|
||||
|
|
|
@ -2,4 +2,8 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
{% endblock %}
|
||||
|
|
|
@ -2,4 +2,8 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
{% endblock %}
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-sm">
|
||||
<thead>
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
<div class="row mt-5">
|
||||
<div class="col">
|
||||
<div class="table-responsive">
|
||||
|
|
|
@ -2,4 +2,8 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
{% endblock %}
|
||||
|
|
|
@ -2,6 +2,18 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% 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 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
@ -25,4 +37,36 @@
|
|||
</div>
|
||||
|
||||
</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 %}
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
<div class="row mt-5">
|
||||
<div class="col">
|
||||
<div class="table-responsive">
|
||||
|
|
|
@ -77,6 +77,10 @@ urlpatterns = [
|
|||
name='user_dids_del'),
|
||||
path('user/credentials/', views_user.UserCredentialsView.as_view(),
|
||||
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/',
|
||||
views_user.UserCredentialsRequiredView.as_view(),
|
||||
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.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.http import HttpResponse
|
||||
from django.contrib import messages
|
||||
from apiregiter import iota
|
||||
from idhub.user.forms import ProfileForm
|
||||
from idhub.mixins import UserView
|
||||
from idhub.models import DID
|
||||
from idhub.models import DID, VerificableCredential
|
||||
|
||||
|
||||
class MyProfile(UserView):
|
||||
|
@ -59,12 +60,62 @@ class UserCredentialsView(MyWallet, TemplateView):
|
|||
subtitle = _('Credentials')
|
||||
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):
|
||||
template_name = "idhub/user/credentials_required.html"
|
||||
subtitle = _('Credentials required')
|
||||
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):
|
||||
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
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ def create_admin_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():
|
||||
|
|
Loading…
Reference in New Issue