From fbb4637a77dc5982b4e694dd31a0aa7d11cec17c Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Thu, 18 Jun 2020 23:17:08 +0200 Subject: initial commit --- client/__init__.py | 0 client/admin.py | 3 +++ client/apps.py | 5 +++++ client/migrations/0001_initial.py | 31 ++++++++++++++++++++++++++++ client/migrations/0002_usercode_user.py | 21 +++++++++++++++++++ client/migrations/__init__.py | 0 client/models.py | 18 +++++++++++++++++ client/templates/client/approve.html | 18 +++++++++++++++++ client/templates/client/index.html | 36 +++++++++++++++++++++++++++++++++ client/tests.py | 3 +++ client/urls.py | 8 ++++++++ client/views.py | 32 +++++++++++++++++++++++++++++ 12 files changed, 175 insertions(+) create mode 100644 client/__init__.py create mode 100644 client/admin.py create mode 100644 client/apps.py create mode 100644 client/migrations/0001_initial.py create mode 100644 client/migrations/0002_usercode_user.py create mode 100644 client/migrations/__init__.py create mode 100644 client/models.py create mode 100644 client/templates/client/approve.html create mode 100644 client/templates/client/index.html create mode 100644 client/tests.py create mode 100644 client/urls.py create mode 100644 client/views.py (limited to 'client') diff --git a/client/__init__.py b/client/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/client/admin.py b/client/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/client/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/client/apps.py b/client/apps.py new file mode 100644 index 0000000..4f5a8a5 --- /dev/null +++ b/client/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ClientConfig(AppConfig): + name = 'client' diff --git a/client/migrations/0001_initial.py b/client/migrations/0001_initial.py new file mode 100644 index 0000000..d680877 --- /dev/null +++ b/client/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 3.0.7 on 2020-06-18 16:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Document', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('code', models.IntegerField(default=0)), + ], + options={ + 'permissions': [('approved', 'The user is approved')], + }, + ), + migrations.CreateModel( + name='UserCode', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('code', models.IntegerField(default=0)), + ], + ), + ] diff --git a/client/migrations/0002_usercode_user.py b/client/migrations/0002_usercode_user.py new file mode 100644 index 0000000..aaaf193 --- /dev/null +++ b/client/migrations/0002_usercode_user.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.7 on 2020-06-18 16:41 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('client', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='usercode', + name='user', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/client/migrations/__init__.py b/client/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/client/models.py b/client/models.py new file mode 100644 index 0000000..970c489 --- /dev/null +++ b/client/models.py @@ -0,0 +1,18 @@ +from django.db import models +from django.contrib.auth.models import User + +# Create your models here. + + +class Document(models.Model): + code = models.IntegerField(default=0) + + class Meta: + permissions = [ + ("approved", "The user is approved") + ] + + +class UserCode(models.Model): + code = models.IntegerField(default=0) + user = models.ForeignKey(User, default=None, on_delete=models.CASCADE) diff --git a/client/templates/client/approve.html b/client/templates/client/approve.html new file mode 100644 index 0000000..026a66d --- /dev/null +++ b/client/templates/client/approve.html @@ -0,0 +1,18 @@ +{% extends 'registration/base.html' %} + +{% block title %}Approva{% endblock %} + +{% block nav %} + +{% endblock %} + +{% block content %} +{{ code }} +{% endblock %} \ No newline at end of file diff --git a/client/templates/client/index.html b/client/templates/client/index.html new file mode 100644 index 0000000..2c55dbc --- /dev/null +++ b/client/templates/client/index.html @@ -0,0 +1,36 @@ +{% extends 'registration/base.html' %} + +{% block title %}Home{% endblock %} + +{%block nav%} + +{% endblock%} + +{% block content %} +{% if user.is_authenticated %} + {% if user.is_staff %} + Ciao {{ user.username }}! +

admin + logout

+ {% elif perms.client.approved %} + Ciao {{ user.username }}! +

logout

+ {% else %} + Il tuo utente non e` ancora stato approvato. +

approva + logout

+ {% endif %} +{% else %} +

Non hai fatto il login

+

login + registrazione

+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/client/tests.py b/client/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/client/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/client/urls.py b/client/urls.py new file mode 100644 index 0000000..4e9f08e --- /dev/null +++ b/client/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), + path('approve', views.approve, name='approve') +] diff --git a/client/views.py b/client/views.py new file mode 100644 index 0000000..5a8f808 --- /dev/null +++ b/client/views.py @@ -0,0 +1,32 @@ +from random import randint + +from django.shortcuts import render + +from .models import UserCode + +# Create your views here. + + +def index(request): + context = {} + return render(request, 'client/index.html', context) + + +def approve(request): + context = {} + if not (request.user.is_staff or request.user.has_perm('approved')): + users = UserCode.objects.filter(user=request.user) + code = None + if (len(users) == 0): + while (True): + code = randint(100000, 999999) + if len(UserCode.objects.filter(code=code)) == 0: + break + userCode = UserCode(user=request.user, code=code) + userCode.save() + else: + code = UserCode.objects.filter(user=request.user)[0].code + context = {'code': 'U' + str(code), } + return render(request, 'client/approve.html', context) + else: + return render(request, 'client/index.html', context) -- cgit v1.2.1