Checkpoint

This commit is contained in:
Daniel Armengod 2023-10-03 05:47:00 +02:00
parent 8f04bc16db
commit 29fd0aedeb
11 changed files with 286 additions and 16 deletions

View File

@ -1,3 +1,5 @@
from django.contrib import admin
# Register your models here.
from .models import AppUser
admin.site.register(AppUser)

24
idhub/forms.py Normal file
View File

@ -0,0 +1,24 @@
from django import forms
from .models import AppUser
class UserForm(forms.Form):
first_name = forms.CharField()
last_name = forms.CharField()
email = forms.EmailField()
date_joined = forms.DateField()
# Extra data:
afiliacio = forms.CharField()
@classmethod
def from_user(cls, user: AppUser):
d = {
"first_name": user.django_user.first_name,
"last_name": user.django_user.last_name,
"email": user.django_user.email,
"date_joined": user.django_user.date_joined,
"afiliacio": "lareputa"
}
return cls(d)

View File

@ -0,0 +1,56 @@
# Generated by Django 4.2.5 on 2023-10-02 15:55
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)),
],
),
]

View File

@ -2,9 +2,12 @@ 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
@ -14,15 +17,39 @@ class Event(models.Model):
kind = "PLACEHOLDER"
class DID(models.Model):
class ExternallyStoredModel(models.Model):
pass
# Any models which inherit from this class are stored in wallet-kit, not in the Django ORM
class Meta:
abstract = True
@staticmethod
def from_json(json_serialization):
# Construct an instance of this class by de-serialization from data returned by wallet-kit.
# Must be implemented by any deriving class.
raise NotImplementedError()
class DID(ExternallyStoredModel):
did_string = models.CharField(max_length=250)
# kind = "KEY|JWK|WEB|EBSI|CHEQD|IOTA"
class VerifiableCredential(models.Model):
class VerifiableCredential(ExternallyStoredModel):
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) # Probably not a FK but the DID directly
did_subject = models.CharField(max_length=250) # Probably not a FK but the DID directly

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="{% url 'user' %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
</body>
</html>

View File

@ -0,0 +1,7 @@
<!-- templates/registration/login.html -->
<h2>Log In</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Log In</button>
</form>

View File

@ -1,5 +1,4 @@
from django.urls import path
from . import views
urlpatterns = [

View File

@ -1,15 +1,30 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from .models import User
from django.urls import reverse
from .models import AppUser
from .forms import UserForm
from django.shortcuts import redirect, render
from django.contrib.auth.decorators import login_required
def index(request):
return redirect("/user")
@login_required
def user(request):
uid = request.user
user = User.get(uid)
context = { userdata: user }
return render(request, "polls/user.html", context)
current_user: AppUser = request.user.appuser
if request.method == "POST":
form = UserForm(request.POST)
if form.is_valid():
cdata = form.cleaned_data
current_user.django_user.first_name = cdata['first_name']
current_user.save()
current_user.django_user.save()
return HttpResponseRedirect(reverse("user"))
else:
return render(request, "idhub/user-details.html", {"form": form})
elif request.method == "GET":
form = UserForm.from_user(current_user)
return render(request, "idhub/user-details.html", {"form": form})

View File

@ -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'

View File

@ -16,8 +16,11 @@ 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"))
path("accounts/login/", auth_views.LoginView.as_view()),
path('', include("idhub.urls"))
]

View File

@ -4,8 +4,8 @@
/user/roles [GET] -> vista de rols (????)
/user/gdpr [GET] -> info de la gdpr
/user/wallet/dids [GET, PUT]
/user/wallet/dids/<id:integer> [DELETE]
/user/wallet/dids [GET, POST]
/user/wallet/dids/<id:integer> [GET, DELETE]
/user/credentials [GET]
/user/credentials/<id:integer> [GET, DELETE]
/user/credentials/request [GET, POST]