diff --git a/idhub/admin.py b/idhub/admin.py index 8c38f3f..049dca3 100644 --- a/idhub/admin.py +++ b/idhub/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin -# Register your models here. +from .models import AppUser + +admin.site.register(AppUser) diff --git a/idhub/migrations/0001_initial.py b/idhub/migrations/0001_initial.py new file mode 100644 index 0000000..df5fa3c --- /dev/null +++ b/idhub/migrations/0001_initial.py @@ -0,0 +1,56 @@ +# Generated by Django 4.2.5 on 2023-10-03 15:28 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='DID', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('did_string', models.CharField(max_length=250)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Event', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('timestamp', models.DateTimeField()), + ], + ), + migrations.CreateModel( + name='VerifiableCredential', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('id_string', models.CharField(max_length=250)), + ('data', models.TextField()), + ('verified', models.BooleanField()), + ('created_on', models.DateTimeField()), + ('did_issuer', models.CharField(max_length=250)), + ('did_subject', models.CharField(max_length=250)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='AppUser', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('django_user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/idhub/models.py b/idhub/models.py index 88f6ec2..fb053bc 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -2,27 +2,41 @@ from django.db import models from django.contrib.auth.models import User as DjangoUser -class User(DjangoUser): +class AppUser(models.Model): # Ya incluye "first_name", "last_name", "email", y "date_joined" heredando de la clase User de django. # Falta ver que más información hay que añadir a nuestros usuarios, como los roles etc. + django_user = models.OneToOneField(DjangoUser, on_delete=models.CASCADE) + + # Extra data, segun entidad/organizacion pass class Event(models.Model): # Para los "audit logs" que se requieren en las pantallas. timestamp = models.DateTimeField() - kind = "PLACEHOLDER" + # Los eventos no tienen relación con otros objetos a nivel de BBDD. + event_data = models.CharField(max_length=250) class DID(models.Model): did_string = models.CharField(max_length=250) - # kind = "KEY|JWK|WEB|EBSI|CHEQD|IOTA" + label = models.CharField(max_length=50) + owner = models.ForeignKey(AppUser, on_delete=models.CASCADE) + # kind = "KEY|WEB" class VerifiableCredential(models.Model): id_string = models.CharField(max_length=250) - data = models.TextField() verified = models.BooleanField() created_on = models.DateTimeField() - did_issuer = models.ForeignKey(DID, on_delete=models.PROTECT) - did_subject = models.ForeignKey(DID, on_delete=models.PROTECT) + did_issuer = models.CharField(max_length=250) + did_subject = models.CharField(max_length=250) + owner = models.ForeignKey(AppUser, on_delete=models.CASCADE) + data = models.TextField() + + +class VCTemplate(models.Model): + wkit_template_id = models.CharField(max_length=250) + data = models.TextField() + + diff --git a/idhub/templates/idhub/user-details.html b/idhub/templates/idhub/user-details.html new file mode 100644 index 0000000..4f9b2b1 --- /dev/null +++ b/idhub/templates/idhub/user-details.html @@ -0,0 +1,14 @@ + + + + + Title + + +
+ {% csrf_token %} + {{ form }} + +
+ + \ No newline at end of file diff --git a/idhub/templates/registration/login.html b/idhub/templates/registration/login.html new file mode 100644 index 0000000..12aa9cf --- /dev/null +++ b/idhub/templates/registration/login.html @@ -0,0 +1,7 @@ + +

Log In

+
+{% csrf_token %} +{{ form.as_p }} + +
\ No newline at end of file diff --git a/idhub/urls.py b/idhub/urls.py index 83f7050..d877cbf 100644 --- a/idhub/urls.py +++ b/idhub/urls.py @@ -21,7 +21,6 @@ from .views import LoginView from .admin import views as views_admin from .user import views as views_user - app_name = 'idhub' urlpatterns = [ diff --git a/idhub/views.py b/idhub/views.py index ebbbb99..83d7ff3 100644 --- a/idhub/views.py +++ b/idhub/views.py @@ -1,4 +1,3 @@ - from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ from django.contrib.auth import views as auth_views diff --git a/trustchain_idhub/settings.py b/trustchain_idhub/settings.py index d9713d3..3f4e7bf 100644 --- a/trustchain_idhub/settings.py +++ b/trustchain_idhub/settings.py @@ -37,9 +37,9 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'idhub' 'django_extensions', 'bootstrap4', + 'idhub' ] MIDDLEWARE = [ diff --git a/trustchain_idhub/settings_orig.py b/trustchain_idhub/settings_orig.py new file mode 100644 index 0000000..232dde7 --- /dev/null +++ b/trustchain_idhub/settings_orig.py @@ -0,0 +1,123 @@ +""" +Django settings for trustchain_idhub project. + +Generated by 'django-admin startproject' using Django 4.2.5. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-os^a#c(i*z8*=o4#b%xsno97_!pqsv*or_5&lcga7&+u53(p92' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'trustchain_idhub.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'trustchain_idhub.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/trustchain_idhub/urls.py b/trustchain_idhub/urls.py index 4dce27e..f2fdc05 100644 --- a/trustchain_idhub/urls.py +++ b/trustchain_idhub/urls.py @@ -18,6 +18,9 @@ Including another URLconf # from django.contrib import admin from django.urls import path, include +from django.contrib.auth import views as auth_views + + urlpatterns = [ # path('django-admin/', admin.site.urls), path('', include('idhub.urls')), diff --git a/trustchain_walletkit/TENANT_CFG_TEMPLATE b/trustchain_walletkit/TENANT_CFG_TEMPLATE new file mode 100644 index 0000000..00b3372 --- /dev/null +++ b/trustchain_walletkit/TENANT_CFG_TEMPLATE @@ -0,0 +1,15 @@ +{ + "issuerApiUrl": "http://localhost:8080/issuer-api/default", + "issuerClientName": "PANGEA Issuer Portal", + "issuerDid": null, + "issuerUiUrl": "http://localhost:5000", + "wallets": { + "walt.id": { + "description": "walt.id web wallet", + "id": "walt.id", + "presentPath": "api/siop/initiatePresentation", + "receivePath": "api/siop/initiateIssuance", + "url": "http://localhost:3000" + } + } +} \ No newline at end of file diff --git a/trustchain_walletkit/__init__.py b/trustchain_walletkit/__init__.py new file mode 100644 index 0000000..02d0144 --- /dev/null +++ b/trustchain_walletkit/__init__.py @@ -0,0 +1,52 @@ +from pathlib import Path + +import requests +import json + +WALLETKITD = 'http://localhost:8080/' +ISSUER = f'{WALLETKITD}issuer-api/default/' +VERIFIER = f'{WALLETKITD}verifier-api/default/' + +default_ctype_header = { + 'Content-Type': 'application/json', # specify the type of data you're sending + 'Accept': 'application/json', # specify the type of data you can accept +} + + +def include_str(path): + with open(path, "r") as f: + return f.read().strip() + + +# Create DID for tenant +# Valid methods: 'key'|'web' +def user_create_did(did_method): + url = f'{ISSUER}config/did/create' + data = { + 'method': did_method + } + response = requests.post(url, json=data, headers=default_ctype_header) + response.raise_for_status() + return response.text + + +def admin_create_template(template_name, template_body): + url = f'{ISSUER}config/templates/{template_name}' + body = template_body + response = requests.post(url, data=body, headers=default_ctype_header) + response.raise_for_status() + return + + +def user_issue_vc(vc_name, vc_params): + url = f'{ISSUER}credentials/issuance/request' + # ... + # TODO examine cross-device issuance workflow + pass + + + + + +TENANT_CFG_TMEPLATE = include_str("./TENANT_CFG_TEMPLATE") + diff --git a/urls_provisional b/urls_provisional index 38921fb..43f0677 100644 --- a/urls_provisional +++ b/urls_provisional @@ -1,11 +1,11 @@ /user/event-log [GET] -> vista d'esdeveniments sense enllaços rapids a les accions -/user [GET, POST] -> vista de dades personals +/user/dashboard [GET, POST] -> vista de dades personals /user/roles [GET] -> vista de rols (????) /user/gdpr [GET] -> info de la gdpr -/user/wallet/dids [GET, PUT] -/user/wallet/dids/ [DELETE] +/user/wallet/dids [GET, POST] +/user/wallet/dids/ [GET, DELETE] /user/credentials [GET] /user/credentials/ [GET, DELETE] /user/credentials/request [GET, POST]