aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--accounts/__init__.py0
-rw-r--r--accounts/admin.py3
-rw-r--r--accounts/apps.py5
-rw-r--r--accounts/migrations/__init__.py0
-rw-r--r--accounts/models.py3
-rw-r--r--accounts/templates/accounts/signup.html12
-rw-r--r--accounts/tests.py3
-rw-r--r--accounts/urls.py7
-rw-r--r--accounts/views.py10
-rw-r--r--client/__init__.py0
-rw-r--r--client/admin.py3
-rw-r--r--client/apps.py5
-rw-r--r--client/migrations/0001_initial.py31
-rw-r--r--client/migrations/0002_usercode_user.py21
-rw-r--r--client/migrations/__init__.py0
-rw-r--r--client/models.py18
-rw-r--r--client/templates/client/approve.html18
-rw-r--r--client/templates/client/index.html36
-rw-r--r--client/tests.py3
-rw-r--r--client/urls.py8
-rw-r--r--client/views.py32
-rw-r--r--manage.py21
-rw-r--r--manager/__init__.py0
-rw-r--r--manager/asgi.py16
-rw-r--r--manager/settings.py125
-rw-r--r--manager/urls.py25
-rw-r--r--manager/wsgi.py16
-rw-r--r--server/__init__.py0
-rw-r--r--server/admin.py3
-rw-r--r--server/apps.py5
-rw-r--r--server/migrations/__init__.py0
-rw-r--r--server/models.py3
-rw-r--r--server/templates/server/approve_user.html34
-rw-r--r--server/templates/server/index.html61
-rw-r--r--server/templates/server/user_list.html36
-rw-r--r--server/tests.py3
-rw-r--r--server/urls.py9
-rw-r--r--server/views.py100
-rw-r--r--templates/registration/base.html19
-rw-r--r--templates/registration/login.html12
41 files changed, 708 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7668361
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+**/__pycache__
+**/*.pyc
diff --git a/accounts/__init__.py b/accounts/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/__init__.py
diff --git a/accounts/admin.py b/accounts/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/accounts/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/accounts/apps.py b/accounts/apps.py
new file mode 100644
index 0000000..9b3fc5a
--- /dev/null
+++ b/accounts/apps.py
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class AccountsConfig(AppConfig):
+ name = 'accounts'
diff --git a/accounts/migrations/__init__.py b/accounts/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/migrations/__init__.py
diff --git a/accounts/models.py b/accounts/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/accounts/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/accounts/templates/accounts/signup.html b/accounts/templates/accounts/signup.html
new file mode 100644
index 0000000..e1591aa
--- /dev/null
+++ b/accounts/templates/accounts/signup.html
@@ -0,0 +1,12 @@
+{% extends 'registration/base.html' %}
+
+{% block title %}Iscriviti{% endblock %}
+
+{% block content %}
+ <h2>Iscriviti</h2>
+ <form method="post">
+ {% csrf_token %}
+ {{ form.as_p }}
+ <button class="btn waves-effect waves-light" type="submit">Invia</button>
+ </form>
+{% endblock %} \ No newline at end of file
diff --git a/accounts/tests.py b/accounts/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/accounts/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/accounts/urls.py b/accounts/urls.py
new file mode 100644
index 0000000..d89128b
--- /dev/null
+++ b/accounts/urls.py
@@ -0,0 +1,7 @@
+from django.urls import path
+
+from . import views
+
+urlpatterns = [
+ path('signup/', views.SignUp.as_view(), name='signup'),
+]
diff --git a/accounts/views.py b/accounts/views.py
new file mode 100644
index 0000000..0483fad
--- /dev/null
+++ b/accounts/views.py
@@ -0,0 +1,10 @@
+from django.shortcuts import render
+from django.contrib.auth.forms import UserCreationForm
+from django.urls import reverse_lazy
+from django.views import generic
+
+
+class SignUp(generic.CreateView):
+ form_class = UserCreationForm
+ success_url = reverse_lazy('login')
+ template_name = 'accounts/signup.html'
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)
diff --git a/manage.py b/manage.py
new file mode 100644
index 0000000..00806fc
--- /dev/null
+++ b/manage.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'manager.settings')
+ try:
+ from django.core.management import execute_from_command_line
+ except ImportError as exc:
+ raise ImportError(
+ "Couldn't import Django. Are you sure it's installed and "
+ "available on your PYTHONPATH environment variable? Did you "
+ "forget to activate a virtual environment?"
+ ) from exc
+ execute_from_command_line(sys.argv)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/manager/__init__.py b/manager/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/manager/__init__.py
diff --git a/manager/asgi.py b/manager/asgi.py
new file mode 100644
index 0000000..7400648
--- /dev/null
+++ b/manager/asgi.py
@@ -0,0 +1,16 @@
+"""
+ASGI config for manager project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'manager.settings')
+
+application = get_asgi_application()
diff --git a/manager/settings.py b/manager/settings.py
new file mode 100644
index 0000000..169c56e
--- /dev/null
+++ b/manager/settings.py
@@ -0,0 +1,125 @@
+"""
+Django settings for manager project.
+
+Generated by 'django-admin startproject' using Django 3.0.7.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.0/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/3.0/ref/settings/
+"""
+
+import os
+
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'b4ns!4$%k2w%h=a&p+w6*a4(t_rkna4ax8^s66vzxtrr&b!lb#'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+ 'server.apps.ServerConfig',
+ 'accounts.apps.AccountsConfig',
+ 'client.apps.ClientConfig',
+ '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 = 'manager.urls'
+
+TEMPLATES = [
+ {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [os.path.join(BASE_DIR, 'templates')],
+ '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 = 'manager.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+ }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/3.0/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/3.0/topics/i18n/
+
+LANGUAGE_CODE = 'it-ch'
+
+TIME_ZONE = 'Europe/Zurich'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/3.0/howto/static-files/
+
+STATIC_URL = '/static/'
+LOGIN_REDIRECT_URL = '/'
+LOGOUT_REDIRECT_URL = '/'
diff --git a/manager/urls.py b/manager/urls.py
new file mode 100644
index 0000000..a2c0ebf
--- /dev/null
+++ b/manager/urls.py
@@ -0,0 +1,25 @@
+"""manager URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/3.0/topics/http/urls/
+Examples:
+Function views
+ 1. Add an import: from my_app import views
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
+Class-based views
+ 1. Add an import: from other_app.views import Home
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
+Including another URLconf
+ 1. Import the include() function: from django.urls import include, path
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
+"""
+from django.contrib import admin
+from django.urls import path, include
+
+urlpatterns = [
+ path('', include('client.urls')),
+ path('server/', include('server.urls')),
+ path('accounts/', include('accounts.urls')),
+ path('accounts/', include('django.contrib.auth.urls')),
+ path('admin/', admin.site.urls),
+]
diff --git a/manager/wsgi.py b/manager/wsgi.py
new file mode 100644
index 0000000..74a48b4
--- /dev/null
+++ b/manager/wsgi.py
@@ -0,0 +1,16 @@
+"""
+WSGI config for manager project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'manager.settings')
+
+application = get_wsgi_application()
diff --git a/server/__init__.py b/server/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/server/__init__.py
diff --git a/server/admin.py b/server/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/server/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/server/apps.py b/server/apps.py
new file mode 100644
index 0000000..f6bd99a
--- /dev/null
+++ b/server/apps.py
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class ServerConfig(AppConfig):
+ name = 'server'
diff --git a/server/migrations/__init__.py b/server/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/server/migrations/__init__.py
diff --git a/server/models.py b/server/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/server/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/server/templates/server/approve_user.html b/server/templates/server/approve_user.html
new file mode 100644
index 0000000..ae9dc8b
--- /dev/null
+++ b/server/templates/server/approve_user.html
@@ -0,0 +1,34 @@
+{% extends 'registration/base.html' %}
+
+{% block title %}Admin - Approva Utente{% endblock %}
+
+{% block nav %}
+<nav>
+ <div class="nav-wrapper">
+ <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a>
+ <a href="{% url 'server'%}" class="breadcrumb">Admin</a>
+ <a href="#!" class="breadcrumb">Approva Utente</a>
+ <ul class="right hide-on-med-and-down">
+ <li>{{ user.username}}</li>
+ <li><a href="{% url 'logout' %}"><i class="material-icons">exit_to_app</i></a></li>
+ </ul>
+ </div>
+</nav>
+{% endblock %}
+
+{% block content %}
+<p>Inserire un codice per riga</p>
+<ul class="collection">
+{% for i in messages %}
+ <li class="collection-item">{{ i }}</li>
+{% endfor %}
+</ul>
+<form action="{% url 'uapprove'%}" method="post">
+ {% csrf_token %}
+ <textarea name="codes" class="materialize-textarea"></textarea>
+ <br><br>
+ <button type="submit" class="btn waves-effect waves-light">Invia
+ <i class="material-icons right">send</i>
+ </button>
+</form>
+{% endblock %} \ No newline at end of file
diff --git a/server/templates/server/index.html b/server/templates/server/index.html
new file mode 100644
index 0000000..4790a1d
--- /dev/null
+++ b/server/templates/server/index.html
@@ -0,0 +1,61 @@
+{% extends 'registration/base.html' %}
+
+{% block title %}Admin{% endblock %}
+
+{% block nav %}
+<nav>
+ <div class="nav-wrapper">
+ <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a>
+ <a href="#!" class="breadcrumb">Admin</a>
+ <ul class="right hide-on-med-and-down">
+ <li>{{ user.username}}</li>
+ <li><a href="{% url 'logout' %}"><i class="material-icons">exit_to_app</i></a></li>
+ </ul>
+ </div>
+</nav>
+{% endblock %}
+
+{% block content %}
+<div class="row">
+ <div class="col s6">
+ <div class="card large">
+ <div class="card-content">
+ <p>
+ <table>
+ <tr>
+ <th>Username</th>
+ <th>Nome</th>
+ <th>Cognome</th>
+ <th>Codice</th>
+ <th>Stato</th>
+ </tr>
+ {% for user in users %}
+ <tr>
+ {% for att in user %}
+ <td>{{att}}</td>
+ {% endfor %}
+ </tr>
+ {% endfor %}
+ </table>
+ </p>
+ </div>
+ <div class="card-action">
+ <a href="{% url 'ulist' %}">Lista utenti</a>
+ <a href="{% url 'uapprove' %}">Approva utente</a>
+ </div>
+ </div>
+ </div>
+ <div class="col s6">
+ <div class="card large">
+ <div class="card-content">
+ <p>I am a very simple card. I am good at containing small bits of information.
+ I am convenient because I require little markup to use effectively.</p>
+ </div>
+ <div class="card-action">
+ <a href="{% url 'ulist' %}">Lista documenti</a>
+ <a href="{% url 'uapprove' %}">Approva documento</a>
+ </div>
+ </div>
+ </div>
+</div>
+{% endblock %} \ No newline at end of file
diff --git a/server/templates/server/user_list.html b/server/templates/server/user_list.html
new file mode 100644
index 0000000..daf7303
--- /dev/null
+++ b/server/templates/server/user_list.html
@@ -0,0 +1,36 @@
+{% extends 'registration/base.html' %}
+
+{% block title %}Admin - Lista Utenti{% endblock %}
+
+{% block nav %}
+<nav>
+ <div class="nav-wrapper">
+ <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a>
+ <a href="{% url 'server'%}" class="breadcrumb">Admin</a>
+ <a href="#!" class="breadcrumb">Lista Utenti</a>
+ <ul class="right hide-on-med-and-down">
+ <li>{{ user.username}}</li>
+ <li><a href="{% url 'logout' %}"><i class="material-icons">exit_to_app</i></a></li>
+ </ul>
+ </div>
+</nav>
+{% endblock %}
+
+{% block content %}
+<table>
+ <tr>
+ <th>Username</th>
+ <th>Nome</th>
+ <th>Cognome</th>
+ <th>Codice</th>
+ <th>Stato</th>
+ </tr>
+ {% for user in users %}
+ <tr>
+ {% for att in user %}
+ <td>{{att}}</td>
+ {% endfor %}
+ </tr>
+ {% endfor %}
+</table>
+{% endblock %} \ No newline at end of file
diff --git a/server/tests.py b/server/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/server/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/server/urls.py b/server/urls.py
new file mode 100644
index 0000000..a41b346
--- /dev/null
+++ b/server/urls.py
@@ -0,0 +1,9 @@
+from django.urls import path
+
+from . import views
+
+urlpatterns = [
+ path('', views.index, name='server'),
+ path('uapprove', views.uapprove, name='uapprove'),
+ path('ulist', views.ulist, name='ulist'),
+]
diff --git a/server/views.py b/server/views.py
new file mode 100644
index 0000000..ab94fd6
--- /dev/null
+++ b/server/views.py
@@ -0,0 +1,100 @@
+from django.shortcuts import render
+from client.models import UserCode
+from django.contrib.auth.models import Group, Permission, User
+
+# Create your views here.
+
+
+def index(request):
+ context = {}
+ if (request.user.is_staff):
+ parent_group = request.user.groups.values_list('name', flat=True)[
+ 0]
+ users = User.objects.filter(groups__name=parent_group)
+ out = []
+ for user in users:
+ code = ""
+ if len(UserCode.objects.filter(user=user)) > 0:
+ code = 'U' + str(UserCode.objects.filter(user=user)[0].code)
+ status = ""
+ if user.is_staff:
+ status = "Capo"
+ elif user.has_perm("client.approved"):
+ status = "Attivo"
+ else:
+ status = "In attesa"
+ out.append([user.username, user.first_name,
+ user.last_name, code, status])
+ context = {'users': out}
+ return render(request, 'server/index.html', context)
+ else:
+ return render(request, 'client/index.html', context)
+
+
+def uapprove(request):
+ context = {}
+ if (request.user.is_staff):
+ if request.method == "POST":
+ parent_group = request.user.groups.values_list('name', flat=True)[
+ 0]
+ group = Group.objects.get(name=parent_group)
+ permission = Permission.objects.get(codename='approved')
+ data = request.POST["codes"]
+ data += " "
+ data = data.split("\n")
+ for i in range(len(data)):
+ if not data[i].startswith("U"):
+ data[i] = data[i] + " - Formato errato"
+ elif not data[i][1:-1].isdigit():
+ data[i] = data[i] + " - Formato errato"
+ elif int(data[i][1:-1]) < 100000 or int(data[i][1:-1]) > 999999:
+ data[i] = data[i] + " - Formato errato"
+ elif len(UserCode.objects.filter(code=data[i][1:-1])) == 0:
+ data[i] = data[i] + " - Invalido"
+ else:
+ user = UserCode.objects.filter(code=data[i][1:-1])[0].user
+ if len(user.groups.values_list('name', flat=True)) == 0:
+ user.groups.add(group)
+ user.user_permissions.add(permission)
+ data[i] = data[i] + " - Ok"
+ else:
+ if user.groups.values_list('name', flat=True)[0] == parent_group:
+ user.user_permissions.add(permission)
+ data[i] = data[i] + " - Gia` aggiunto"
+ else:
+ user.groups.clear()
+ user.groups.add(group)
+ user.user_permissions.add(permission)
+ data[i] = data[i] + " - Ok, cambio branca"
+
+ context = {'messages': data}
+
+ return render(request, 'server/approve_user.html', context)
+ else:
+ return render(request, 'client/index.html', context)
+
+
+def ulist(request):
+ context = {}
+ if (request.user.is_staff):
+ parent_group = request.user.groups.values_list('name', flat=True)[
+ 0]
+ users = User.objects.filter(groups__name=parent_group)
+ out = []
+ for user in users:
+ code = ""
+ if len(UserCode.objects.filter(user=user)) > 0:
+ code = 'U' + str(UserCode.objects.filter(user=user)[0].code)
+ status = ""
+ if user.is_staff:
+ status = "Capo"
+ elif user.has_perm("approved"):
+ status = "Attivo"
+ else:
+ status = "In attesa"
+ out.append([user.username, user.first_name,
+ user.last_name, code, status])
+ context = {'users': out}
+ return render(request, 'server/user_list.html', context)
+ else:
+ return render(request, 'client/index.html', context)
diff --git a/templates/registration/base.html b/templates/registration/base.html
new file mode 100644
index 0000000..51dad17
--- /dev/null
+++ b/templates/registration/base.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+ <meta charset="utf-8">
+ <title>{% block title %}Scout Brega{% endblock %}</title>
+</head>
+<body>
+ {% block nav %}
+ {% endblock %}
+ <main style="margin-left: 10px;margin-right: 10px;margin-top: 10px;">
+ {% block content %}
+ {% endblock %}
+ </main>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
+</body>
+</html> \ No newline at end of file
diff --git a/templates/registration/login.html b/templates/registration/login.html
new file mode 100644
index 0000000..71880b3
--- /dev/null
+++ b/templates/registration/login.html
@@ -0,0 +1,12 @@
+{% extends 'registration/base.html' %}
+
+{% block title %}Login{% endblock %}
+
+{% block content %}
+<h2>Login</h2>
+<form method="post">
+ {% csrf_token %}
+ {{ form.as_p }}
+ <button class="btn waves-effect waves-light" type="submit">Login</button>
+</form>
+{% endblock %} \ No newline at end of file