aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-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
11 files changed, 254 insertions, 0 deletions
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)