diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2020-06-18 23:17:08 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2020-06-18 23:17:08 +0200 |
commit | fbb4637a77dc5982b4e694dd31a0aa7d11cec17c (patch) | |
tree | 2b277a09a8dacff187211cacfad7da5b5a3dda9b /client | |
download | scout-subs-fbb4637a77dc5982b4e694dd31a0aa7d11cec17c.tar.gz scout-subs-fbb4637a77dc5982b4e694dd31a0aa7d11cec17c.zip |
initial commit
Diffstat (limited to 'client')
-rw-r--r-- | client/__init__.py | 0 | ||||
-rw-r--r-- | client/admin.py | 3 | ||||
-rw-r--r-- | client/apps.py | 5 | ||||
-rw-r--r-- | client/migrations/0001_initial.py | 31 | ||||
-rw-r--r-- | client/migrations/0002_usercode_user.py | 21 | ||||
-rw-r--r-- | client/migrations/__init__.py | 0 | ||||
-rw-r--r-- | client/models.py | 18 | ||||
-rw-r--r-- | client/templates/client/approve.html | 18 | ||||
-rw-r--r-- | client/templates/client/index.html | 36 | ||||
-rw-r--r-- | client/tests.py | 3 | ||||
-rw-r--r-- | client/urls.py | 8 | ||||
-rw-r--r-- | client/views.py | 32 |
12 files changed, 175 insertions, 0 deletions
diff --git a/client/__init__.py b/client/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/client/__init__.py 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 --- /dev/null +++ b/client/migrations/__init__.py 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 %} +<nav> + <div class="nav-wrapper"> + <div class="col s12"> + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a href="#!" class="breadcrumb">Approva</a> + </div> + </div> +</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%} +<nav> + <div class="nav-wrapper"> + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <ul class="right hide-on-med-and-down"> + <li>{{ user.username}}</li> + <li><a href="{% url 'logout' %}">Logout</a></li> + </ul> + </div> +</nav> +{% endblock%} + +{% block content %} +{% if user.is_authenticated %} + {% if user.is_staff %} + Ciao {{ user.username }}! + <p><a class="waves-effect waves-light btn" href="{% url 'server' %}">admin</a> + <a class="waves-effect waves-light btn" href="{% url 'logout' %}">logout</a></p> + {% elif perms.client.approved %} + Ciao {{ user.username }}! + <p><a class="waves-effect waves-light btn" href="{% url 'logout' %}">logout</a></p> + {% else %} + Il tuo utente non e` ancora stato approvato. + <p><a class="waves-effect waves-light btn" href="{% url 'approve' %}">approva</a> + <a class="waves-effect waves-light btn" href="{% url 'logout' %}">logout</a></p> + {% endif %} +{% else %} + <p>Non hai fatto il login</p> + <p><a class="waves-effect waves-light btn" href="{% url 'login' %}">login</a> + <a class="waves-effect waves-light btn" href="{% url 'signup' %}">registrazione</a></p> +{% 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) |