From af6f58869b8dc8d69b5cdd1afd163eed3004ceaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C4=9Bj=20Zeman?= <zemanm98@students.zcu.cz>
Date: Tue, 3 May 2022 11:56:59 +0200
Subject: [PATCH 1/8] prefix path fix and ld-logs new body and head devices fix

---
 server/sql_app/api/devices_web.py  | 2 +-
 server/sql_app/api/licenses_web.py | 2 +-
 server/sql_app/api/pcs_web.py      | 2 +-
 server/sql_app/api/teams_web.py    | 2 +-
 server/sql_app/api/usb_logs.py     | 4 ++--
 server/sql_app/api/usb_logs_web.py | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/server/sql_app/api/devices_web.py b/server/sql_app/api/devices_web.py
index 2ab3dc0..0c6fd0a 100644
--- a/server/sql_app/api/devices_web.py
+++ b/server/sql_app/api/devices_web.py
@@ -16,7 +16,7 @@ models.Base.metadata.create_all(bind=engine)
 templates = Jinja2Templates(directory="templates/devices")
 
 # prefix used for all endpoints in this file
-device_web = APIRouter(prefix="/api/v1")
+device_web = APIRouter(prefix="")
 
 
 # Dependency
diff --git a/server/sql_app/api/licenses_web.py b/server/sql_app/api/licenses_web.py
index 4316dd6..523dbd8 100644
--- a/server/sql_app/api/licenses_web.py
+++ b/server/sql_app/api/licenses_web.py
@@ -17,7 +17,7 @@ templates = Jinja2Templates(directory="templates/licenses")
 device_templates = Jinja2Templates(directory="templates/devices")
 
 # prefix used for all endpoints in this file
-licenses_web = APIRouter(prefix="/api/v1")
+licenses_web = APIRouter(prefix="")
 
 
 # Dependency
diff --git a/server/sql_app/api/pcs_web.py b/server/sql_app/api/pcs_web.py
index a5243fd..b9c614f 100644
--- a/server/sql_app/api/pcs_web.py
+++ b/server/sql_app/api/pcs_web.py
@@ -14,7 +14,7 @@ models.Base.metadata.create_all(bind=engine)
 templates = Jinja2Templates(directory="templates/pcs")
 
 # prefix used for all endpoints in this file
-pcs_web = APIRouter(prefix="/api/v1")
+pcs_web = APIRouter(prefix="")
 
 
 # Dependency
diff --git a/server/sql_app/api/teams_web.py b/server/sql_app/api/teams_web.py
index d3b23d0..30c1acf 100644
--- a/server/sql_app/api/teams_web.py
+++ b/server/sql_app/api/teams_web.py
@@ -15,7 +15,7 @@ models.Base.metadata.create_all(bind=engine)
 templates = Jinja2Templates(directory="templates/teams")
 
 # prefix used for all endpoints in this file
-teams_web = APIRouter(prefix="/api/v1")
+teams_web = APIRouter(prefix="")
 
 
 # Dependency
diff --git a/server/sql_app/api/usb_logs.py b/server/sql_app/api/usb_logs.py
index 2bf4067..e61697f 100644
--- a/server/sql_app/api/usb_logs.py
+++ b/server/sql_app/api/usb_logs.py
@@ -48,9 +48,9 @@ def create_ld_logs(log: schemas.LDTempBase, db: Session = Depends(get_db)):
     head_dev = crud.find_head_device(db, log.head_device)
     body_dev = crud.find_body_device(db, log.body_device)
     if head_dev is None:
-        crud.create_head_device(db, log.head_device)
+        head_dev = crud.create_head_device(db, log.head_device)
     if body_dev is None:
-        crud.create_body_device(db, log.body_device)
+        body_dev = crud.create_body_device(db, log.body_device)
 
     pc = crud.find_pc(db, log.username, log.hostname)
     if pc is None:
diff --git a/server/sql_app/api/usb_logs_web.py b/server/sql_app/api/usb_logs_web.py
index b745384..0559e59 100644
--- a/server/sql_app/api/usb_logs_web.py
+++ b/server/sql_app/api/usb_logs_web.py
@@ -15,7 +15,7 @@ models.Base.metadata.create_all(bind=engine)
 templates = Jinja2Templates(directory="templates/usb-logs")
 
 # prefix used for all endpoints in this file
-usblogs_web = APIRouter(prefix="/api/v1")
+usblogs_web = APIRouter(prefix="")
 
 
 # Dependency
-- 
GitLab


From 4858e9ee8b1da8db610e920f829d4ae5f1c74d9a Mon Sep 17 00:00:00 2001
From: Matej Zeman <zeman339@gmail.com>
Date: Tue, 3 May 2022 17:02:35 +0200
Subject: [PATCH 2/8] Views navigation fix

---
 server/templates/devices/devicelicense.html   |  2 +-
 server/templates/devices/devices.html         | 14 +++++++-------
 server/templates/licenses/license_create.html |  2 +-
 server/templates/licenses/licenses.html       |  8 ++++----
 server/templates/pcs/pcs.html                 | 10 +++++-----
 server/templates/pcs/pcteam.html              |  2 +-
 server/templates/teams/team_create.html       |  2 +-
 server/templates/teams/teams.html             | 10 +++++-----
 server/templates/usb-logs/logs.html           | 10 +++++-----
 9 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/server/templates/devices/devicelicense.html b/server/templates/devices/devicelicense.html
index 054c75b..f3780b1 100644
--- a/server/templates/devices/devicelicense.html
+++ b/server/templates/devices/devicelicense.html
@@ -9,7 +9,7 @@
     <p>Product ID: {{device.product_id}}</p>
     <p>Serial Number: {{device.serial_number}}</p>
 </h6>
-<form action="/api/v1/devices-web/{{device.id}}" method="post">
+<form action="/devices-web/{{device.id}}" method="post">
   <label for="lic">Licenses:</label>
   <select id="lic" name="lic">
       {% for license in licenses %}
diff --git a/server/templates/devices/devices.html b/server/templates/devices/devices.html
index b5afad1..4d4bd6e 100644
--- a/server/templates/devices/devices.html
+++ b/server/templates/devices/devices.html
@@ -7,14 +7,14 @@
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
-      <option value="/api/v1/logs-web">Logs</option>
-      <option value="/api/v1/devices-web">Devices</option>
-      <option value="/api/v1/teams-web">Teams</option>
-      <option value="/api/v1/pcs-web">PCs</option>
+      <option value="/logs-web">Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
   </select>
   <input type="submit" value="OK">
 </form>
-<form action="/api/v1/devices-web" method="post">
+<form action="/devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
     <datalist id="licenses">
@@ -35,7 +35,7 @@
     </TR>
     {% for i in range(devs) %}
     <TR>
-        <TD class="ID"><a href="/api/v1/device-license/{{devices[i].id}}">{{devices[i].id}}</a></TD>
+        <TD class="ID"><a href="/device-license/{{devices[i].id}}">{{devices[i].id}}</a></TD>
         <TD class="Vendor ID">{{devices[i].vendor_id}}</TD>
         <TD class="Product ID">{{devices[i].product_id}}</TD>
         <TD class="Serial Number">{{devices[i].serial_number}}</TD>
@@ -53,7 +53,7 @@
         <TD class="Product ID"></TD>
         <TD class="Serial Number"></TD>
         <TD class="License">
-            <form action="/api/v1/license-create" method="get">
+            <form action="/license-create" method="get">
                 <input type="submit" value="Add">
             </form>
         </TD>
diff --git a/server/templates/licenses/license_create.html b/server/templates/licenses/license_create.html
index a68f7d8..709fb52 100644
--- a/server/templates/licenses/license_create.html
+++ b/server/templates/licenses/license_create.html
@@ -5,7 +5,7 @@
     <title>Create a License</title>
 </head>
 <body>
-<form action="/api/v1/licenses-web" method="post">
+<form action="/licenses-web" method="post">
   <label for="name">Name:</label><br>
   <input type="text" id="name" name="name"><br><br>
     <label for="expdate">Expiration Date</label>
diff --git a/server/templates/licenses/licenses.html b/server/templates/licenses/licenses.html
index e456ab0..477983b 100644
--- a/server/templates/licenses/licenses.html
+++ b/server/templates/licenses/licenses.html
@@ -7,10 +7,10 @@
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
-      <option value="/api/v1/logs-web">Logs</option>
-      <option value="/api/v1/devices-web">Devices</option>
-      <option value="/api/v1/teams-web">Teams</option>
-      <option value="/api/v1/pcs-web">PCs</option>
+      <option value="/logs-web">Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
   </select>
   <input type="submit" value="OK">
 </form>
diff --git a/server/templates/pcs/pcs.html b/server/templates/pcs/pcs.html
index 3b0a2eb..9b7c168 100644
--- a/server/templates/pcs/pcs.html
+++ b/server/templates/pcs/pcs.html
@@ -7,10 +7,10 @@
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
-      <option value="/api/v1/logs-web">Logs</option>
-      <option value="/api/v1/devices-web">Devices</option>
-      <option value="/api/v1/teams-web">Teams</option>
-      <option value="/api/v1/pcs-web">PCs</option>
+      <option value="/logs-web">Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -23,7 +23,7 @@
     </TR>
     {% for pc in pcs %}
     <TR>
-        <TD class="ID"><a href="/api/v1/pc-team/{{pc.id}}">{{pc.id}}</a></TD>
+        <TD class="ID"><a href="/pc-team/{{pc.id}}">{{pc.id}}</a></TD>
         <TD class="Vendor ID">{{pc.username}}</TD>
         <TD class="Product ID">{{pc.hostname}}</TD>
         {% if pc.team == None %}
diff --git a/server/templates/pcs/pcteam.html b/server/templates/pcs/pcteam.html
index 8559cbc..eebc129 100644
--- a/server/templates/pcs/pcteam.html
+++ b/server/templates/pcs/pcteam.html
@@ -8,7 +8,7 @@
 <h6><p>Username: {{pc.username}}</p>
     <p>Hostname: {{pc.hostname}}</p>
 </h6>
-<form action="/api/v1/pcs-web/{{pc.id}}" method="post">
+<form action="/pcs-web/{{pc.id}}" method="post">
   <label for="team">Teams:</label>
   <select id="team" name="team">
       {% for team in teams %}
diff --git a/server/templates/teams/team_create.html b/server/templates/teams/team_create.html
index 3ae1c25..16dcc0a 100644
--- a/server/templates/teams/team_create.html
+++ b/server/templates/teams/team_create.html
@@ -5,7 +5,7 @@
     <title>Create a Team</title>
 </head>
 <body>
-<form action="/api/v1/teams-web" method="post">
+<form action="/teams-web" method="post">
   <label for="name">Name:</label><br>
   <input type="text" id="name" name="name"><br><br>
   <input type="submit" value="Submit">
diff --git a/server/templates/teams/teams.html b/server/templates/teams/teams.html
index 644f6d9..f3fe57a 100644
--- a/server/templates/teams/teams.html
+++ b/server/templates/teams/teams.html
@@ -7,10 +7,10 @@
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
-      <option value="/api/v1/logs-web">Logs</option>
-      <option value="/api/v1/devices-web">Devices</option>
-      <option value="/api/v1/teams-web">Teams</option>
-      <option value="/api/v1/pcs-web">PCs</option>
+      <option value="/logs-web">Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -26,7 +26,7 @@
     </TR>
     {% endfor %}
 </table>
-<form action="/api/v1/team-create" method="get">
+<form action="/team-create" method="get">
     <input type="submit" value="Add">
 </form>
 </body>
diff --git a/server/templates/usb-logs/logs.html b/server/templates/usb-logs/logs.html
index 722c811..ff75863 100644
--- a/server/templates/usb-logs/logs.html
+++ b/server/templates/usb-logs/logs.html
@@ -7,14 +7,14 @@
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
-      <option value="/api/v1/logs-web">Logs</option>
-      <option value="/api/v1/devices-web">Devices</option>
-      <option value="/api/v1/teams-web">Teams</option>
-      <option value="/api/v1/pcs-web">PCs</option>
+      <option value="/logs-web">Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
   </select>
   <input type="submit" value="OK">
 </form>
-<form action="/api/v1/logs-web" method="post">
+<form action="/logs-web" method="post">
   <label for="pc">PC:</label>
   <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
     <datalist id="pcs">
-- 
GitLab


From c78ad6f2353029028a8a9f69a5827e4fbc21c9b6 Mon Sep 17 00:00:00 2001
From: Matej Zeman <zeman339@gmail.com>
Date: Wed, 4 May 2022 13:30:59 +0200
Subject: [PATCH 3/8] re #9708 Login logic with fastapi-jwt

---
 server/requirements.txt               |   3 +-
 server/sql_app/api/devices_web.py     | 122 +++++++++++++++++++++++---
 server/templates/devices/devices.html |   3 +
 server/templates/devices/login.html   |  16 ++++
 4 files changed, 131 insertions(+), 13 deletions(-)
 create mode 100644 server/templates/devices/login.html

diff --git a/server/requirements.txt b/server/requirements.txt
index acad635..a1e5719 100644
--- a/server/requirements.txt
+++ b/server/requirements.txt
@@ -4,4 +4,5 @@ SQLAlchemy==1.4.32
 uvicorn==0.17.6
 psycopg2-binary==2.8.6
 jinja2==3.1.1
-python-multipart==0.0.5
\ No newline at end of file
+python-multipart==0.0.5
+fastapi-jwt-auth=0.5.0
\ No newline at end of file
diff --git a/server/sql_app/api/devices_web.py b/server/sql_app/api/devices_web.py
index 0c6fd0a..f47bc28 100644
--- a/server/sql_app/api/devices_web.py
+++ b/server/sql_app/api/devices_web.py
@@ -1,14 +1,15 @@
-from typing import List
-
-from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form
-from sqlalchemy.orm import Session
-from sql_app import crud, models, schemas
 from datetime import datetime
-from ..database import SessionLocal, engine
-from fastapi import FastAPI, Request
+
+from fastapi import Depends, APIRouter, Form
+from fastapi import Request
 from fastapi.responses import HTMLResponse
-from fastapi.staticfiles import StaticFiles
 from fastapi.templating import Jinja2Templates
+from fastapi_jwt_auth import AuthJWT
+from pydantic import BaseModel
+from sqlalchemy.orm import Session
+
+from sql_app import crud, models
+from ..database import SessionLocal, engine
 
 models.Base.metadata.create_all(bind=engine)
 
@@ -19,6 +20,32 @@ templates = Jinja2Templates(directory="templates/devices")
 device_web = APIRouter(prefix="")
 
 
+
+class Settings(BaseModel):
+    authjwt_secret_key: str = "secret"
+    # Configure application to store and get JWT from cookies
+    authjwt_token_location: set = {"cookies"}
+    # Disable CSRF Protection for this example. default is True
+    authjwt_cookie_csrf_protect: bool = False
+
+
+@AuthJWT.load_config
+def get_config():
+    return Settings()
+
+
+fake_users_db = {
+    "admin": {
+        "username": "admin",
+        "password": "admin"
+    },
+    "editor": {
+        "username": "editor",
+        "password": "editor"
+    },
+}
+
+
 # Dependency
 def get_db():
     db = SessionLocal()
@@ -28,16 +55,86 @@ def get_db():
         db.close()
 
 
+@device_web.get("/token", response_class=HTMLResponse)
+async def login_get(request: Request):
+    return templates.TemplateResponse("login.html", {"request": request})
+
+
+@device_web.post("/token", response_class=HTMLResponse)
+async def login(username: str = Form(...), password: str = Form(...), Authorize: AuthJWT = Depends()):
+    user_dict = fake_users_db.get(username)
+
+    access_token = Authorize.create_access_token(subject=username, expires_time=False)
+    refresh_token = Authorize.create_refresh_token(subject=username, expires_time=False)
+
+    # Set the JWT cookies in the response
+    Authorize.set_access_cookies(access_token)
+    Authorize.set_refresh_cookies(refresh_token)
+    return """
+    <html>
+        <head>
+            <title>Some HTML in here</title>
+        </head>
+        <body>
+            <h1>Look ma! HTML!</h1>
+            <form action="/devices-web" method="get">
+                <input type="submit" value="Login" />
+            </form>
+        </body>
+    </html>
+    """
+
+
+@device_web.post('/refresh')
+def refresh(Authorize: AuthJWT = Depends()):
+    Authorize.jwt_refresh_token_required()
+
+    current_user = Authorize.get_jwt_subject()
+    new_access_token = Authorize.create_access_token(subject=current_user)
+    # Set the JWT cookies in the response
+    Authorize.set_access_cookies(new_access_token)
+    return {"msg": "The token has been refresh"}
+
+
+@device_web.get('/logout', response_class=HTMLResponse)
+def logout(Authorize: AuthJWT = Depends()):
+    """
+    Because the JWT are stored in an httponly cookie now, we cannot
+    log the user out by simply deleting the cookies in the frontend.
+    We need the backend to send us a response to delete the cookies.
+    """
+    Authorize.jwt_required()
+
+    Authorize.unset_jwt_cookies()
+    return """
+        <html>
+            <head>
+                <title>Some HTML in here</title>
+            </head>
+            <body>
+                <h1>Look ma! HTML!</h1>
+                <form action="/devices-web" method="get">
+                    <input type="submit" value="Login" />
+                </form>
+            </body>
+        </html>
+        """
+
+
 @device_web.get("/devices-web", response_class=HTMLResponse)
-async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
+async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
+                       Authorize: AuthJWT = Depends()):
     """
     Returns template with all devices and its current states
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+
     devices = crud.get_devices(db, skip=skip, limit=limit)
     statuses = []
     # adding state for each device in list
     for i in range(0, len(devices)):
-        statuses.append(devices[i].logs[len(devices[i].logs)-1].status)
+        statuses.append(devices[i].logs[len(devices[i].logs) - 1].status)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
     return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices,
                                                        "statuses": statuses, "licenses": licenses})
@@ -63,8 +160,9 @@ async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic:
     for i in range(0, len(def_devices)):
         statuses.append(def_devices[i].logs[len(def_devices[i].logs) - 1].status)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("devices.html", {"request": request, "devs": len(def_devices), "devices": def_devices,
-                                                       "statuses": statuses, "licenses": licenses})
+    return templates.TemplateResponse("devices.html",
+                                      {"request": request, "devs": len(def_devices), "devices": def_devices,
+                                       "statuses": statuses, "licenses": licenses})
 
 
 @device_web.get("/device-license/{device_id}", response_class=HTMLResponse)
diff --git a/server/templates/devices/devices.html b/server/templates/devices/devices.html
index 4d4bd6e..4c4774e 100644
--- a/server/templates/devices/devices.html
+++ b/server/templates/devices/devices.html
@@ -14,6 +14,9 @@
   </select>
   <input type="submit" value="OK">
 </form>
+<form action="/token" method="get">
+    <input type="submit" value="Login" />
+</form>
 <form action="/devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
diff --git a/server/templates/devices/login.html b/server/templates/devices/login.html
new file mode 100644
index 0000000..622990b
--- /dev/null
+++ b/server/templates/devices/login.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Login</title>
+</head>
+<body>
+<form action="/token" method="post">
+  <label for="username">Username:</label><br>
+  <input type="text" id="username" name="username"><br><br>
+    <label for="password">Expiration Date</label>
+  <input type="text" id="password" name="password">
+  <input type="submit" value="Submit">
+</form>
+</body>
+</html>
\ No newline at end of file
-- 
GitLab


From 2fe004b11cd6d2407e4756fb93bb029d9e7ecccf Mon Sep 17 00:00:00 2001
From: Matej Zeman <zeman339@gmail.com>
Date: Thu, 5 May 2022 14:49:38 +0200
Subject: [PATCH 4/8] re #9708 updated requirements. Added logout and template
 versions for host users.

---
 server/requirements.txt                       |   2 +-
 server/sql_app/api/auth.py                    | 112 +++++++++++++++++
 server/sql_app/api/devices_web.py             | 116 ++----------------
 server/sql_app/api/ld_logs_web.py             |   0
 server/sql_app/api/licenses_web.py            |  13 +-
 server/sql_app/api/pcs_web.py                 |  19 +--
 server/sql_app/api/teams_web.py               |  19 +--
 server/sql_app/main.py                        |   2 +
 server/templates/{devices => auth}/login.html |   2 +-
 server/templates/devices/devices.html         |   9 +-
 server/templates/devices/devices_normal.html  |  62 ++++++++++
 server/templates/licenses/licenses.html       |  10 ++
 server/templates/pcs/pcs.html                 |  10 ++
 server/templates/pcs/pcs_normal.html          |  48 ++++++++
 server/templates/teams/teams.html             |  10 ++
 server/templates/teams/teams_normal.html      |  40 ++++++
 server/templates/usb-logs/logs.html           |  10 ++
 17 files changed, 351 insertions(+), 133 deletions(-)
 create mode 100644 server/sql_app/api/auth.py
 create mode 100644 server/sql_app/api/ld_logs_web.py
 rename server/templates/{devices => auth}/login.html (91%)
 create mode 100644 server/templates/devices/devices_normal.html
 create mode 100644 server/templates/pcs/pcs_normal.html
 create mode 100644 server/templates/teams/teams_normal.html

diff --git a/server/requirements.txt b/server/requirements.txt
index a1e5719..e70f09c 100644
--- a/server/requirements.txt
+++ b/server/requirements.txt
@@ -5,4 +5,4 @@ uvicorn==0.17.6
 psycopg2-binary==2.8.6
 jinja2==3.1.1
 python-multipart==0.0.5
-fastapi-jwt-auth=0.5.0
\ No newline at end of file
+fastapi-jwt-auth==0.5.0
\ No newline at end of file
diff --git a/server/sql_app/api/auth.py b/server/sql_app/api/auth.py
new file mode 100644
index 0000000..8178130
--- /dev/null
+++ b/server/sql_app/api/auth.py
@@ -0,0 +1,112 @@
+
+
+from fastapi import Depends, APIRouter, Form
+from fastapi import Request
+from fastapi.responses import HTMLResponse
+from fastapi.templating import Jinja2Templates
+from fastapi.responses import HTMLResponse
+from fastapi_jwt_auth import AuthJWT
+from pydantic import BaseModel
+
+
+# Path to html templates used in this file
+templates = Jinja2Templates(directory="templates/auth")
+
+# prefix used for all endpoints in this file
+auth = APIRouter(prefix="")
+
+
+
+class Settings(BaseModel):
+    authjwt_secret_key: str = "secret"
+    # Configure application to store and get JWT from cookies
+    authjwt_token_location: set = {"cookies"}
+    # Disable CSRF Protection for this example. default is True
+    authjwt_cookie_csrf_protect: bool = False
+
+
+@AuthJWT.load_config
+def get_config():
+    return Settings()
+
+
+fake_users_db = {
+    "admin": {
+        "username": "admin",
+        "password": "admin"
+    }
+}
+
+
+@auth.get("/login", response_class=HTMLResponse)
+async def login_get(request: Request):
+    return templates.TemplateResponse("login.html", {"request": request})
+
+
+@auth.post("/login", response_class=HTMLResponse)
+async def login(username: str = Form(...), password: str = Form(...), Authorize: AuthJWT = Depends()):
+    user_dict = fake_users_db.get(username)
+
+    if user_dict != None:
+        if user_dict["username"] == username and user_dict["password"] == password:
+            access_token = Authorize.create_access_token(subject="admin", expires_time=False)
+            refresh_token = Authorize.create_refresh_token(subject="admin", expires_time=False)
+        else:
+            access_token = Authorize.create_access_token(subject="host", expires_time=False)
+            refresh_token = Authorize.create_refresh_token(subject="host", expires_time=False)
+    else:
+        access_token = Authorize.create_access_token(subject="host", expires_time=False)
+        refresh_token = Authorize.create_refresh_token(subject="host", expires_time=False)
+
+    # Set the JWT cookies in the response
+    Authorize.set_access_cookies(access_token)
+    Authorize.set_refresh_cookies(refresh_token)
+    return """
+    <html>
+        <head>
+            <title>Login</title>
+        </head>
+        <body>
+            <h1>Logged in</h1>
+            <form action="/logs-web" method="get">
+                <input type="submit" value="Back" />
+            </form>
+        </body>
+    </html>
+    """
+
+
+@auth.post('/refresh')
+def refresh(Authorize: AuthJWT = Depends()):
+    Authorize.jwt_refresh_token_required()
+
+    current_user = Authorize.get_jwt_subject()
+    new_access_token = Authorize.create_access_token(subject=current_user)
+    # Set the JWT cookies in the response
+    Authorize.set_access_cookies(new_access_token)
+    return {"msg": "The token has been refresh"}
+
+
+@auth.get('/logout', response_class=HTMLResponse)
+def logout(Authorize: AuthJWT = Depends()):
+    """
+    Because the JWT are stored in an httponly cookie now, we cannot
+    log the user out by simply deleting the cookies in the frontend.
+    We need the backend to send us a response to delete the cookies.
+    """
+    Authorize.jwt_optional()
+
+    Authorize.unset_jwt_cookies()
+    return """
+        <html>
+            <head>
+                <title>Logout</title>
+            </head>
+            <body>
+                <h1>Logged Out</h1>
+                <form action="/logs-web" method="get">
+                    <input type="submit" value="Back" />
+                </form>
+            </body>
+        </html>
+        """
\ No newline at end of file
diff --git a/server/sql_app/api/devices_web.py b/server/sql_app/api/devices_web.py
index f47bc28..f10de1b 100644
--- a/server/sql_app/api/devices_web.py
+++ b/server/sql_app/api/devices_web.py
@@ -2,12 +2,12 @@ from datetime import datetime
 
 from fastapi import Depends, APIRouter, Form
 from fastapi import Request
-from fastapi.responses import HTMLResponse
+from fastapi.responses import HTMLResponse, RedirectResponse
 from fastapi.templating import Jinja2Templates
 from fastapi_jwt_auth import AuthJWT
 from pydantic import BaseModel
 from sqlalchemy.orm import Session
-
+from sql_app.api.auth import fake_users_db
 from sql_app import crud, models
 from ..database import SessionLocal, engine
 
@@ -20,32 +20,6 @@ templates = Jinja2Templates(directory="templates/devices")
 device_web = APIRouter(prefix="")
 
 
-
-class Settings(BaseModel):
-    authjwt_secret_key: str = "secret"
-    # Configure application to store and get JWT from cookies
-    authjwt_token_location: set = {"cookies"}
-    # Disable CSRF Protection for this example. default is True
-    authjwt_cookie_csrf_protect: bool = False
-
-
-@AuthJWT.load_config
-def get_config():
-    return Settings()
-
-
-fake_users_db = {
-    "admin": {
-        "username": "admin",
-        "password": "admin"
-    },
-    "editor": {
-        "username": "editor",
-        "password": "editor"
-    },
-}
-
-
 # Dependency
 def get_db():
     db = SessionLocal()
@@ -55,72 +29,6 @@ def get_db():
         db.close()
 
 
-@device_web.get("/token", response_class=HTMLResponse)
-async def login_get(request: Request):
-    return templates.TemplateResponse("login.html", {"request": request})
-
-
-@device_web.post("/token", response_class=HTMLResponse)
-async def login(username: str = Form(...), password: str = Form(...), Authorize: AuthJWT = Depends()):
-    user_dict = fake_users_db.get(username)
-
-    access_token = Authorize.create_access_token(subject=username, expires_time=False)
-    refresh_token = Authorize.create_refresh_token(subject=username, expires_time=False)
-
-    # Set the JWT cookies in the response
-    Authorize.set_access_cookies(access_token)
-    Authorize.set_refresh_cookies(refresh_token)
-    return """
-    <html>
-        <head>
-            <title>Some HTML in here</title>
-        </head>
-        <body>
-            <h1>Look ma! HTML!</h1>
-            <form action="/devices-web" method="get">
-                <input type="submit" value="Login" />
-            </form>
-        </body>
-    </html>
-    """
-
-
-@device_web.post('/refresh')
-def refresh(Authorize: AuthJWT = Depends()):
-    Authorize.jwt_refresh_token_required()
-
-    current_user = Authorize.get_jwt_subject()
-    new_access_token = Authorize.create_access_token(subject=current_user)
-    # Set the JWT cookies in the response
-    Authorize.set_access_cookies(new_access_token)
-    return {"msg": "The token has been refresh"}
-
-
-@device_web.get('/logout', response_class=HTMLResponse)
-def logout(Authorize: AuthJWT = Depends()):
-    """
-    Because the JWT are stored in an httponly cookie now, we cannot
-    log the user out by simply deleting the cookies in the frontend.
-    We need the backend to send us a response to delete the cookies.
-    """
-    Authorize.jwt_required()
-
-    Authorize.unset_jwt_cookies()
-    return """
-        <html>
-            <head>
-                <title>Some HTML in here</title>
-            </head>
-            <body>
-                <h1>Look ma! HTML!</h1>
-                <form action="/devices-web" method="get">
-                    <input type="submit" value="Login" />
-                </form>
-            </body>
-        </html>
-        """
-
-
 @device_web.get("/devices-web", response_class=HTMLResponse)
 async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
                        Authorize: AuthJWT = Depends()):
@@ -136,8 +44,12 @@ async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Se
     for i in range(0, len(devices)):
         statuses.append(devices[i].logs[len(devices[i].logs) - 1].status)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices,
-                                                       "statuses": statuses, "licenses": licenses})
+    if current_user == "admin":
+        return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices,
+                                                           "statuses": statuses, "licenses": licenses})
+    else:
+        return templates.TemplateResponse("devices_normal.html", {"request": request, "devs": len(devices), "devices": devices,
+                                                           "statuses": statuses, "licenses": licenses})
 
 
 @device_web.post("/devices-web", response_class=HTMLResponse)
@@ -177,18 +89,10 @@ async def connect_dev_lic(request: Request, device_id: int, db: Session = Depend
 
 
 @device_web.post("/devices-web/{device_id}", response_class=HTMLResponse)
-async def connect_post(request: Request, device_id: int, lic: str = Form(...), skip: int = 0, limit: int = 100,
-                       db: Session = Depends(get_db)):
+async def connect_post(device_id: int, lic: str = Form(...), db: Session = Depends(get_db)):
     """
     Endpoint called from template for connecting device with license. Adds entry to devices_licenses
     table and returns template with all devices in database
     """
     crud.create_device_license(db, device_id, int(lic), datetime.now())
-    devices = crud.get_devices(db, skip=skip, limit=limit)
-    statuses = []
-    # adding state for each device in list
-    for i in range(0, len(devices)):
-        statuses.append(devices[i].logs[len(devices[i].logs) - 1].status)
-    licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices,
-                                                       "statuses": statuses, "licenses": licenses})
+    return RedirectResponse("/devices-web")
diff --git a/server/sql_app/api/ld_logs_web.py b/server/sql_app/api/ld_logs_web.py
new file mode 100644
index 0000000..e69de29
diff --git a/server/sql_app/api/licenses_web.py b/server/sql_app/api/licenses_web.py
index 523dbd8..cebf250 100644
--- a/server/sql_app/api/licenses_web.py
+++ b/server/sql_app/api/licenses_web.py
@@ -6,7 +6,7 @@ from datetime import date
 from sql_app import crud, models, schemas
 from ..database import SessionLocal, engine
 from fastapi import FastAPI, Request
-from fastapi.responses import HTMLResponse
+from fastapi.responses import HTMLResponse, RedirectResponse
 from fastapi.staticfiles import StaticFiles
 from fastapi.templating import Jinja2Templates
 
@@ -47,18 +47,11 @@ async def read_licenses_web(request: Request, skip: int = 0, limit: int = 100, d
 
 
 @licenses_web.post("/licenses-web", response_class=HTMLResponse)
-def create_license(request: Request, name: str = Form(...), expdate: date = Form(...), skip: int = 0, limit: int = 100,
-                   db: Session = Depends(get_db)):
+def create_license(name: str = Form(...), expdate: date = Form(...), db: Session = Depends(get_db)):
     """
     Endpoint called from create license form. Creates new license and returns template with all licenses in database
     """
     db_license = crud.create_license(db, name, expdate)
     if db_license is None:
         print("something went wrong")
-    devices = crud.get_devices(db, skip=skip, limit=limit)
-    statuses = []
-    for i in range(0, len(devices)):
-        statuses.append(devices[i].logs[len(devices[i].logs) - 1].status)
-    licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    return device_templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices,
-                                                       "statuses": statuses, "licenses": licenses})
\ No newline at end of file
+    return RedirectResponse("/devices-web")
diff --git a/server/sql_app/api/pcs_web.py b/server/sql_app/api/pcs_web.py
index b9c614f..3a5d66f 100644
--- a/server/sql_app/api/pcs_web.py
+++ b/server/sql_app/api/pcs_web.py
@@ -4,7 +4,8 @@ from sqlalchemy.orm import Session
 from sql_app import crud, models, schemas
 from ..database import SessionLocal, engine
 from fastapi import FastAPI, Request
-from fastapi.responses import HTMLResponse
+from fastapi.responses import HTMLResponse, RedirectResponse
+from fastapi_jwt_auth import AuthJWT
 from fastapi.staticfiles import StaticFiles
 from fastapi.templating import Jinja2Templates
 
@@ -27,12 +28,18 @@ def get_db():
 
 
 @pcs_web.get("/pcs-web", response_class=HTMLResponse)
-async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
+async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
+                   Authorize: AuthJWT = Depends()):
     """
     Returns template with all pcs currently saved in database
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
     pcs = crud.get_pcs(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs})
+    if current_user == "admin":
+        return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs})
+    else:
+        return templates.TemplateResponse("pcs_normal.html", {"request": request, "pcs": pcs})
 
 
 @pcs_web.get("/pc-team/{pc_id}", response_class=HTMLResponse)
@@ -47,11 +54,9 @@ async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(ge
 
 
 @pcs_web.post("/pcs-web/{pc_id}", response_class=HTMLResponse)
-async def connect_post(request: Request, pc_id: int, team: str = Form(...), skip: int = 0, limit: int = 100,
-                       db: Session = Depends(get_db)):
+async def connect_post(pc_id: int, team: str = Form(...), db: Session = Depends(get_db)):
     """
     Endpoint called from within form for connecting pc with team. Updates certain pc with new team.
     """
     old_pc = crud.update_pc(db, pc_id, team)
-    pcs = crud.get_pcs(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs})
+    RedirectResponse("/pcs-web")
diff --git a/server/sql_app/api/teams_web.py b/server/sql_app/api/teams_web.py
index 30c1acf..3d9cfd6 100644
--- a/server/sql_app/api/teams_web.py
+++ b/server/sql_app/api/teams_web.py
@@ -5,7 +5,8 @@ from sqlalchemy.orm import Session
 from sql_app import crud, models, schemas
 from ..database import SessionLocal, engine
 from fastapi import FastAPI, Request
-from fastapi.responses import HTMLResponse
+from fastapi.responses import HTMLResponse, RedirectResponse
+from fastapi_jwt_auth import AuthJWT
 from fastapi.staticfiles import StaticFiles
 from fastapi.templating import Jinja2Templates
 
@@ -28,12 +29,18 @@ def get_db():
 
 
 @teams_web.get("/teams-web", response_class=HTMLResponse)
-async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
+async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
+                       Authorize: AuthJWT = Depends()):
     """
     Returns template with all teams currently saved in database
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
     teams = crud.get_teams(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("teams.html", {"request": request, "teams": teams})
+    if current_user == "admin":
+        return templates.TemplateResponse("teams.html", {"request": request, "teams": teams})
+    else:
+        return templates.TemplateResponse("teams_normal.html", {"request": request, "teams": teams})
 
 
 @teams_web.get("/team-create", response_class=HTMLResponse)
@@ -45,13 +52,11 @@ async def team_create_web(request: Request):
 
 
 @teams_web.post("/teams-web", response_class=HTMLResponse)
-def create_team(request: Request, name: str = Form(...), skip: int = 0, limit: int = 100,
-                   db: Session = Depends(get_db)):
+def create_team(name: str = Form(...), db: Session = Depends(get_db)):
     """
     Endpoint called from within form for creating new team. Creates new team and returns all teams in database
     """
     team = crud.create_team(db, name)
     if team is None:
         print("something went wrong")
-    teams = crud.get_teams(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("teams.html", {"request": request, "teams": teams})
+    RedirectResponse("/teams-web")
diff --git a/server/sql_app/main.py b/server/sql_app/main.py
index d871b3e..774d8eb 100644
--- a/server/sql_app/main.py
+++ b/server/sql_app/main.py
@@ -9,6 +9,7 @@ from sql_app.api.usb_logs import usblogs
 from sql_app.api.usb_logs_web import usblogs_web
 from sql_app.api.teams import teams
 from sql_app.api.teams_web import teams_web
+from sql_app.api.auth import auth
 from fastapi import FastAPI
 
 
@@ -27,6 +28,7 @@ app.include_router(licenses_web)
 app.include_router(pcs_web)
 app.include_router(teams_web)
 app.include_router(usblogs_web)
+app.include_router(auth)
 
 '''
 if __name__ == "__main__":
diff --git a/server/templates/devices/login.html b/server/templates/auth/login.html
similarity index 91%
rename from server/templates/devices/login.html
rename to server/templates/auth/login.html
index 622990b..49fdcdf 100644
--- a/server/templates/devices/login.html
+++ b/server/templates/auth/login.html
@@ -5,7 +5,7 @@
     <title>Login</title>
 </head>
 <body>
-<form action="/token" method="post">
+<form action="/login" method="post">
   <label for="username">Username:</label><br>
   <input type="text" id="username" name="username"><br><br>
     <label for="password">Expiration Date</label>
diff --git a/server/templates/devices/devices.html b/server/templates/devices/devices.html
index 4c4774e..c1abf2d 100644
--- a/server/templates/devices/devices.html
+++ b/server/templates/devices/devices.html
@@ -3,6 +3,7 @@
     <title>Devices Details</title>
 </head>
 <body>
+<div style='float:left'>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -14,9 +15,15 @@
   </select>
   <input type="submit" value="OK">
 </form>
-<form action="/token" method="get">
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
     <input type="submit" value="Login" />
 </form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="/devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
diff --git a/server/templates/devices/devices_normal.html b/server/templates/devices/devices_normal.html
new file mode 100644
index 0000000..18b21a4
--- /dev/null
+++ b/server/templates/devices/devices_normal.html
@@ -0,0 +1,62 @@
+<html>
+<head>
+    <title>Devices Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+<form action="/devices-web" method="post">
+    <label for="lic">License:</label>
+    <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
+    <datalist id="licenses">
+        {% for license in licenses %}
+        <option value="{{license.name}}"></option>
+        {% endfor %}
+    </datalist>
+  <input type="submit" value="Filter">
+</form>
+<table>
+    <TR>
+        <TH>ID</TH>
+        <TH>Vendor ID</TH>
+        <TH>Product ID</TH>
+        <TH>Serial Number</TH>
+        <TH>Licenses</TH>
+        <TH>Status</TH>
+    </TR>
+    {% for i in range(devs) %}
+    <TR>
+        <TD class="ID">{{devices[i].id}}</TD>
+        <TD class="Vendor ID">{{devices[i].vendor_id}}</TD>
+        <TD class="Product ID">{{devices[i].product_id}}</TD>
+        <TD class="Serial Number">{{devices[i].serial_number}}</TD>
+        <TD class="License">
+            {% for lic in devices[i].licenses %}
+                {{lic.licenses.name}}<BR>
+            {% endfor %}
+        </TD>
+        <TD class="Status">{{statuses[i]}}</TD>
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/licenses/licenses.html b/server/templates/licenses/licenses.html
index 477983b..8e5ab8e 100644
--- a/server/templates/licenses/licenses.html
+++ b/server/templates/licenses/licenses.html
@@ -3,6 +3,7 @@
     <title>Licenses Details</title>
 </head>
 <body>
+<div style='float:left'>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -14,6 +15,15 @@
   </select>
   <input type="submit" value="OK">
 </form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/pcs/pcs.html b/server/templates/pcs/pcs.html
index 9b7c168..6532f24 100644
--- a/server/templates/pcs/pcs.html
+++ b/server/templates/pcs/pcs.html
@@ -3,6 +3,7 @@
     <title>Pcs Details</title>
 </head>
 <body>
+<div style='float:left'>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -14,6 +15,15 @@
   </select>
   <input type="submit" value="OK">
 </form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/pcs/pcs_normal.html b/server/templates/pcs/pcs_normal.html
new file mode 100644
index 0000000..bee77d2
--- /dev/null
+++ b/server/templates/pcs/pcs_normal.html
@@ -0,0 +1,48 @@
+<html>
+<head>
+    <title>Pcs Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+<table>
+    <TR>
+        <TH>ID</TH>
+        <TH>Username</TH>
+        <TH>Hostname</TH>
+        <TH>Team</TH>
+    </TR>
+    {% for pc in pcs %}
+    <TR>
+        <TD class="ID">{{pc.id}}</TD>
+        <TD class="Vendor ID">{{pc.username}}</TD>
+        <TD class="Product ID">{{pc.hostname}}</TD>
+        {% if pc.team == None %}
+            <TD class="Team">NONE</TD>
+        {% else %}
+            <TD class="Team">{{pc.team.name}}</TD>
+        {% endif %}
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/teams/teams.html b/server/templates/teams/teams.html
index f3fe57a..77e5052 100644
--- a/server/templates/teams/teams.html
+++ b/server/templates/teams/teams.html
@@ -3,6 +3,7 @@
     <title>Teams Details</title>
 </head>
 <body>
+<div style='float:left'>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -14,6 +15,15 @@
   </select>
   <input type="submit" value="OK">
 </form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/teams/teams_normal.html b/server/templates/teams/teams_normal.html
new file mode 100644
index 0000000..f1a5fc1
--- /dev/null
+++ b/server/templates/teams/teams_normal.html
@@ -0,0 +1,40 @@
+<html>
+<head>
+    <title>Teams Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+<table>
+    <TR>
+        <TH>ID</TH>
+        <TH>Name</TH>
+    </TR>
+    {% for team in teams %}
+    <TR>
+        <TD class="ID">{{team.id}}</TD>
+        <TD class="Vendor ID">{{team.name}}</TD>
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/usb-logs/logs.html b/server/templates/usb-logs/logs.html
index ff75863..7e7e4be 100644
--- a/server/templates/usb-logs/logs.html
+++ b/server/templates/usb-logs/logs.html
@@ -3,6 +3,7 @@
     <title>Logs Details</title>
 </head>
 <body>
+<div style='float:left'>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -14,6 +15,15 @@
   </select>
   <input type="submit" value="OK">
 </form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="/logs-web" method="post">
   <label for="pc">PC:</label>
   <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
-- 
GitLab


From 7fe7be79d4da62e8ab89c487ae57e8d6e0991f7a Mon Sep 17 00:00:00 2001
From: "zemanm98@students.zcu.cz" <Farnhait123*>
Date: Sun, 8 May 2022 10:09:26 +0200
Subject: [PATCH 5/8] Added views for LD logs and forms for connecting body
 devices with licenses.

---
 server/sql_app/api/auth.py                    |  23 ++-
 server/sql_app/api/bodydevices_web.py         | 128 +++++++++++++
 server/sql_app/api/devices_web.py             |  50 ++++-
 server/sql_app/api/ld_logs_web.py             |  73 ++++++++
 server/sql_app/api/licenses_web.py            |   6 +-
 server/sql_app/api/pcs_web.py                 |   9 +-
 server/sql_app/api/teams_web.py               |   9 +-
 server/sql_app/api/usb_logs_web.py            |  10 +-
 server/sql_app/crud.py                        | 173 +++++++++++++++---
 server/sql_app/main.py                        |   6 +-
 server/sql_app/models.py                      |  20 +-
 .../body-devices/body_device_license.html     |  30 +++
 .../templates/body-devices/body_devices.html  |  72 ++++++++
 .../body-devices/body_devices_normal.html     |  63 +++++++
 server/templates/devices/devicelicense.html   |   9 +
 server/templates/devices/devices.html         |   5 +
 server/templates/devices/devices_normal.html  |   5 +
 server/templates/ld-logs/ldlogs.html          |  85 +++++++++
 server/templates/licenses/licenses.html       |   2 +
 server/templates/pcs/pcs.html                 |   5 +
 server/templates/pcs/pcs_normal.html          |   5 +
 server/templates/teams/team_create.html       |   2 +-
 server/templates/teams/teams.html             |   5 +
 server/templates/teams/teams_normal.html      |   5 +
 server/templates/usb-logs/logs.html           |   5 +
 25 files changed, 746 insertions(+), 59 deletions(-)
 create mode 100644 server/sql_app/api/bodydevices_web.py
 create mode 100644 server/templates/body-devices/body_device_license.html
 create mode 100644 server/templates/body-devices/body_devices.html
 create mode 100644 server/templates/body-devices/body_devices_normal.html
 create mode 100644 server/templates/ld-logs/ldlogs.html

diff --git a/server/sql_app/api/auth.py b/server/sql_app/api/auth.py
index 8178130..069d27c 100644
--- a/server/sql_app/api/auth.py
+++ b/server/sql_app/api/auth.py
@@ -1,14 +1,10 @@
-
-
 from fastapi import Depends, APIRouter, Form
 from fastapi import Request
 from fastapi.responses import HTMLResponse
 from fastapi.templating import Jinja2Templates
-from fastapi.responses import HTMLResponse
 from fastapi_jwt_auth import AuthJWT
 from pydantic import BaseModel
 
-
 # Path to html templates used in this file
 templates = Jinja2Templates(directory="templates/auth")
 
@@ -29,7 +25,7 @@ class Settings(BaseModel):
 def get_config():
     return Settings()
 
-
+# admin username and password
 fake_users_db = {
     "admin": {
         "username": "admin",
@@ -40,13 +36,19 @@ fake_users_db = {
 
 @auth.get("/login", response_class=HTMLResponse)
 async def login_get(request: Request):
+    """
+    return html template for login
+    """
     return templates.TemplateResponse("login.html", {"request": request})
 
 
 @auth.post("/login", response_class=HTMLResponse)
 async def login(username: str = Form(...), password: str = Form(...), Authorize: AuthJWT = Depends()):
+    """
+    Endpoint called from login template. Checks if given username and password aligns with admin
+    username and password and returns token for browser according to given username and password
+    """
     user_dict = fake_users_db.get(username)
-
     if user_dict != None:
         if user_dict["username"] == username and user_dict["password"] == password:
             access_token = Authorize.create_access_token(subject="admin", expires_time=False)
@@ -78,8 +80,11 @@ async def login(username: str = Form(...), password: str = Form(...), Authorize:
 
 @auth.post('/refresh')
 def refresh(Authorize: AuthJWT = Depends()):
+    """
+    endpoint for refreshing browser token. Not used at the moment since lifetime of given tokens are
+    unlimited.
+    """
     Authorize.jwt_refresh_token_required()
-
     current_user = Authorize.get_jwt_subject()
     new_access_token = Authorize.create_access_token(subject=current_user)
     # Set the JWT cookies in the response
@@ -90,9 +95,7 @@ def refresh(Authorize: AuthJWT = Depends()):
 @auth.get('/logout', response_class=HTMLResponse)
 def logout(Authorize: AuthJWT = Depends()):
     """
-    Because the JWT are stored in an httponly cookie now, we cannot
-    log the user out by simply deleting the cookies in the frontend.
-    We need the backend to send us a response to delete the cookies.
+    Endpoint for deleting cookie token with acces role.
     """
     Authorize.jwt_optional()
 
diff --git a/server/sql_app/api/bodydevices_web.py b/server/sql_app/api/bodydevices_web.py
new file mode 100644
index 0000000..9b13bb7
--- /dev/null
+++ b/server/sql_app/api/bodydevices_web.py
@@ -0,0 +1,128 @@
+from datetime import datetime
+
+from fastapi import Depends, APIRouter, Form
+from fastapi import Request
+from fastapi.responses import HTMLResponse, RedirectResponse
+from fastapi.templating import Jinja2Templates
+from fastapi_jwt_auth import AuthJWT
+from pydantic import BaseModel
+from sqlalchemy.orm import Session
+from sql_app.api.auth import fake_users_db
+from sql_app import crud, models
+from ..database import SessionLocal, engine
+
+models.Base.metadata.create_all(bind=engine)
+
+# Path to html templates used in this file
+templates = Jinja2Templates(directory="templates/body-devices")
+
+# prefix used for all endpoints in this file
+body_device_web = APIRouter(prefix="")
+
+
+# Dependency
+def get_db():
+    db = SessionLocal()
+    try:
+        yield db
+    finally:
+        db.close()
+
+
+@body_device_web.get("/body-devices-web", response_class=HTMLResponse)
+async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
+                       Authorize: AuthJWT = Depends()):
+    """
+    Returns template with all body devices and its current states
+    """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+
+    devices = crud.get_body_devices(db, skip=skip, limit=limit)
+    statuses = []
+    # adding state for each device in list
+    for i in range(0, len(devices)):
+        statuses.append(devices[i].b_logs[len(devices[i].b_logs) - 1].status)
+    licenses = crud.get_licenses(db, skip=skip, limit=limit)
+    if current_user == "admin":
+        return templates.TemplateResponse("body_devices.html", {"request": request, "devs": len(devices), "devices": devices,
+                                                           "statuses": statuses, "licenses": licenses, "user": current_user})
+    else:
+        current_user = "guest"
+        return templates.TemplateResponse("body_devices_normal.html", {"request": request, "devs": len(devices), "devices": devices,
+                                                           "statuses": statuses, "licenses": licenses, "user": current_user})
+
+
+@body_device_web.post("/body-devices-web", response_class=HTMLResponse)
+async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic: str = Form("all"),
+                         db: Session = Depends(get_db), Authorize: AuthJWT = Depends()):
+    """
+    Endpoint used for filtering body devices by license. returns html template with only
+    body devices that has assigned license defined by user input
+    """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    devices = crud.get_body_devices(db, skip=skip, limit=limit)
+    def_devices = []
+    for dev in devices:
+        for l in dev.debug_licenses:
+            if dev not in def_devices and l.b_licenses.name == lic:
+                def_devices.append(dev)
+    # if input was default all
+    if lic == "all":
+        def_devices = devices
+    statuses = []
+    for i in range(0, len(def_devices)):
+        statuses.append(def_devices[i].b_logs[len(def_devices[i].b_logs) - 1].status)
+    licenses = crud.get_licenses(db, skip=skip, limit=limit)
+    if current_user == "admin":
+        return templates.TemplateResponse("body_devices.html",
+                                          {"request": request, "devs": len(def_devices), "devices": def_devices,
+                                           "statuses": statuses, "licenses": licenses, "user": current_user})
+    else:
+        current_user = "guest"
+        return templates.TemplateResponse("body_devices_normal.html",
+                                          {"request": request, "devs": len(def_devices), "devices": def_devices,
+                                           "statuses": statuses, "licenses": licenses, "user": current_user})
+
+
+@body_device_web.get("/body-device-license/{device_id}", response_class=HTMLResponse)
+async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db)):
+    """
+    Returns template with one body device and all available licenses that can be assigned to it.
+    """
+    device = crud.get_body_device(db, device_id)
+    dev_licenses = crud.get_bodydevice_license(db, device_id)
+    lic_names = []
+    dev_lics = []
+    for dev_lic in dev_licenses:
+        dev_lics.append(dev_lic.b_licenses)
+    for dev_lic in dev_licenses:
+        lic_names.append(dev_lic.b_licenses.name)
+    licenses = crud.get_licenses(db, 0, 100)
+    lic_left = []
+    for lic in licenses:
+        if lic.name not in lic_names and lic not in lic_left:
+            lic_left.append(lic)
+    return templates.TemplateResponse("body_device_license.html",
+                                      {"request": request, "device": device, "licenses": lic_left, "dev_lic": dev_lics})
+
+
+@body_device_web.post("/body-devices-web/{device_id}")
+async def connect_post(device_id: int, lic: str = Form(...), db: Session = Depends(get_db)):
+    """
+    Endpoint called from template for connecting body device with license. Adds entry to bodydevices_licenses
+    table and redirects to body-devices-web endpoint
+    """
+    crud.create_body_device_license(db, device_id, int(lic), datetime.now())
+    return RedirectResponse(url=f"/body-devices-web", status_code=303)
+
+
+@body_device_web.post("/body-devices-web-del/{device_id}")
+async def delete_post(device_id: int, b_lic: str = Form(...), db: Session = Depends(get_db)):
+    """
+    Endpoint called from template for connecting body device with license. Adds entry to devices_licenses
+    table and redirects to body-devices-web endpoint
+    """
+    crud.delete_bodydevice_license(db, device_id, int(b_lic))
+    return RedirectResponse(url=f"/body-devices-web", status_code=303)
\ No newline at end of file
diff --git a/server/sql_app/api/devices_web.py b/server/sql_app/api/devices_web.py
index f10de1b..97c38a5 100644
--- a/server/sql_app/api/devices_web.py
+++ b/server/sql_app/api/devices_web.py
@@ -46,19 +46,22 @@ async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Se
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
     if current_user == "admin":
         return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices,
-                                                           "statuses": statuses, "licenses": licenses})
+                                                           "statuses": statuses, "licenses": licenses, "user": current_user})
     else:
+        current_user = "guest"
         return templates.TemplateResponse("devices_normal.html", {"request": request, "devs": len(devices), "devices": devices,
-                                                           "statuses": statuses, "licenses": licenses})
+                                                                  "statuses": statuses, "licenses": licenses, "user": current_user})
 
 
 @device_web.post("/devices-web", response_class=HTMLResponse)
 async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic: str = Form("all"),
-                         db: Session = Depends(get_db)):
+                         db: Session = Depends(get_db), Authorize: AuthJWT = Depends()):
     """
     Endpoint used for filtering devices by license. returns html template with only
     devices that has assigned license defined by user input
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
     devices = crud.get_devices(db, skip=skip, limit=limit)
     def_devices = []
     for dev in devices:
@@ -72,9 +75,15 @@ async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic:
     for i in range(0, len(def_devices)):
         statuses.append(def_devices[i].logs[len(def_devices[i].logs) - 1].status)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("devices.html",
-                                      {"request": request, "devs": len(def_devices), "devices": def_devices,
-                                       "statuses": statuses, "licenses": licenses})
+    if current_user == "admin":
+        return templates.TemplateResponse("devices.html",
+                                          {"request": request, "devs": len(def_devices), "devices": def_devices,
+                                           "statuses": statuses, "licenses": licenses, "user": current_user})
+    else:
+        current_user = "guest"
+        return templates.TemplateResponse("devices_normal.html",
+                                          {"request": request, "devs": len(def_devices), "devices": def_devices,
+                                           "statuses": statuses, "licenses": licenses, "user": current_user})
 
 
 @device_web.get("/device-license/{device_id}", response_class=HTMLResponse)
@@ -83,16 +92,37 @@ async def connect_dev_lic(request: Request, device_id: int, db: Session = Depend
     Returns template with one device and all available licenses that can be assigned to it.
     """
     device = crud.get_device(db, device_id)
+    dev_licenses = crud.get_device_licenses(db, device_id)
+    lic_names = []
+    dev_lics = []
+    for dev_lic in dev_licenses:
+        dev_lics.append(dev_lic.licenses)
+    for dev_lic in dev_licenses:
+        lic_names.append(dev_lic.licenses.name)
     licenses = crud.get_licenses(db, 0, 100)
+    lic_left = []
+    for lic in licenses:
+        if lic.name not in lic_names and lic not in lic_left:
+            lic_left.append(lic)
     return templates.TemplateResponse("devicelicense.html",
-                                      {"request": request, "device": device, "licenses": licenses})
+                                      {"request": request, "device": device, "licenses": lic_left, "dev_lic": dev_lics})
 
 
-@device_web.post("/devices-web/{device_id}", response_class=HTMLResponse)
+@device_web.post("/devices-web/{device_id}")
 async def connect_post(device_id: int, lic: str = Form(...), db: Session = Depends(get_db)):
     """
     Endpoint called from template for connecting device with license. Adds entry to devices_licenses
-    table and returns template with all devices in database
+    table and redirects to devices-web endpoint
     """
     crud.create_device_license(db, device_id, int(lic), datetime.now())
-    return RedirectResponse("/devices-web")
+    return RedirectResponse(url=f"/devices-web", status_code=303)
+
+
+@device_web.post("/devices-web-del/{device_id}")
+async def delete_post(device_id: int, lic_del: str = Form(...), db: Session = Depends(get_db)):
+    """
+    Endpoint called from template for deleting device-license connection. Adds entry to bodydevices_licenses
+    table and redirects to devices-web endpoint
+    """
+    crud.delete_device_license(db, device_id, int(lic_del))
+    return RedirectResponse(url=f"/devices-web", status_code=303)
diff --git a/server/sql_app/api/ld_logs_web.py b/server/sql_app/api/ld_logs_web.py
index e69de29..fbebfec 100644
--- a/server/sql_app/api/ld_logs_web.py
+++ b/server/sql_app/api/ld_logs_web.py
@@ -0,0 +1,73 @@
+from typing import List
+from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form
+from datetime import datetime
+from sqlalchemy.orm import Session
+from sql_app import crud, models, schemas
+from ..database import SessionLocal, engine
+from fastapi import FastAPI, Request
+from fastapi.responses import HTMLResponse
+from fastapi_jwt_auth import AuthJWT
+from fastapi.staticfiles import StaticFiles
+from fastapi.templating import Jinja2Templates
+
+models.Base.metadata.create_all(bind=engine)
+
+# Path to html templates used in this file
+templates = Jinja2Templates(directory="templates/ld-logs")
+
+# prefix used for all endpoints in this file
+ldlogs_web = APIRouter(prefix="")
+
+
+# Dependency
+def get_db():
+    db = SessionLocal()
+    try:
+        yield db
+    finally:
+        db.close()
+
+
+@ldlogs_web.get("/ldlogs-web", response_class=HTMLResponse)
+async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
+                    Authorize: AuthJWT = Depends()):
+    """
+    Returns template with all usb logs currently saved in database with its pcs, teams and licenses.
+    """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    logs = crud.get_ld_logs(db, skip=skip, limit=limit)
+    pcs = []
+    for log in logs:
+        if log.pc_id not in pcs:
+            pcs.append(log.pc_id)
+    pc_obj = crud.find_pcs(db, pcs)
+    teams = crud.get_teams(db, skip=skip, limit=limit)
+    licenses = crud.get_licenses(db, skip=skip, limit=limit)
+    if current_user != "admin":
+        current_user = "guest"
+    return templates.TemplateResponse("ldlogs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                                      "licenses": licenses, "user": current_user})
+
+
+@ldlogs_web.post("/ldlogs-web", response_class=HTMLResponse)
+async def filter_logs(request: Request, pc: str = Form("all"), team: str = Form("all"), lic: str = Form("all"),
+                      skip: int = 0, limit: int = 100,
+                      db: Session = Depends(get_db), Authorize: AuthJWT = Depends()):
+    """
+    Endpoint used for filtering ld logs by user given form inputs.
+    """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    log = crud.get_filtered_ldlogs(db, pc, team, lic)
+    logs_ids = []
+    for l in log:
+        logs_ids.append(l[0])
+    logs = crud.find_filtered_ldlogs(db, logs_ids)
+    pc_obj = crud.get_pcs(db, skip=skip, limit=limit)
+    teams = crud.get_teams(db, skip=skip, limit=limit)
+    licenses = crud.get_licenses(db, skip=skip, limit=limit)
+    if current_user != "admin":
+        current_user = "guest"
+    return templates.TemplateResponse("ldlogs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                                      "licenses": licenses, "user": current_user})
diff --git a/server/sql_app/api/licenses_web.py b/server/sql_app/api/licenses_web.py
index cebf250..24de037 100644
--- a/server/sql_app/api/licenses_web.py
+++ b/server/sql_app/api/licenses_web.py
@@ -46,12 +46,12 @@ async def read_licenses_web(request: Request, skip: int = 0, limit: int = 100, d
     return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses})
 
 
-@licenses_web.post("/licenses-web", response_class=HTMLResponse)
+@licenses_web.post("/licenses-web")
 def create_license(name: str = Form(...), expdate: date = Form(...), db: Session = Depends(get_db)):
     """
-    Endpoint called from create license form. Creates new license and returns template with all licenses in database
+    Endpoint called from create license form. Creates new license and redirects to devices-web endpoint
     """
     db_license = crud.create_license(db, name, expdate)
     if db_license is None:
         print("something went wrong")
-    return RedirectResponse("/devices-web")
+    return RedirectResponse(url=f"/devices-web", status_code=303)
diff --git a/server/sql_app/api/pcs_web.py b/server/sql_app/api/pcs_web.py
index 3a5d66f..02303ab 100644
--- a/server/sql_app/api/pcs_web.py
+++ b/server/sql_app/api/pcs_web.py
@@ -37,9 +37,10 @@ async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Sessio
     current_user = Authorize.get_jwt_subject()
     pcs = crud.get_pcs(db, skip=skip, limit=limit)
     if current_user == "admin":
-        return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs})
+        return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs, "user": current_user})
     else:
-        return templates.TemplateResponse("pcs_normal.html", {"request": request, "pcs": pcs})
+        current_user = "guest"
+        return templates.TemplateResponse("pcs_normal.html", {"request": request, "pcs": pcs, "user": current_user})
 
 
 @pcs_web.get("/pc-team/{pc_id}", response_class=HTMLResponse)
@@ -53,10 +54,10 @@ async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(ge
                                       {"request": request, "pc": pc, "teams": teams})
 
 
-@pcs_web.post("/pcs-web/{pc_id}", response_class=HTMLResponse)
+@pcs_web.post("/pcs-web/{pc_id}")
 async def connect_post(pc_id: int, team: str = Form(...), db: Session = Depends(get_db)):
     """
     Endpoint called from within form for connecting pc with team. Updates certain pc with new team.
     """
     old_pc = crud.update_pc(db, pc_id, team)
-    RedirectResponse("/pcs-web")
+    return RedirectResponse(url=f"/pcs-web", status_code=303)
diff --git a/server/sql_app/api/teams_web.py b/server/sql_app/api/teams_web.py
index 3d9cfd6..c1752a1 100644
--- a/server/sql_app/api/teams_web.py
+++ b/server/sql_app/api/teams_web.py
@@ -38,9 +38,10 @@ async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Se
     current_user = Authorize.get_jwt_subject()
     teams = crud.get_teams(db, skip=skip, limit=limit)
     if current_user == "admin":
-        return templates.TemplateResponse("teams.html", {"request": request, "teams": teams})
+        return templates.TemplateResponse("teams.html", {"request": request, "teams": teams, "user": current_user})
     else:
-        return templates.TemplateResponse("teams_normal.html", {"request": request, "teams": teams})
+        current_user = "guest"
+        return templates.TemplateResponse("teams_normal.html", {"request": request, "teams": teams, "user": current_user})
 
 
 @teams_web.get("/team-create", response_class=HTMLResponse)
@@ -51,7 +52,7 @@ async def team_create_web(request: Request):
     return templates.TemplateResponse("team_create.html", {"request": request})
 
 
-@teams_web.post("/teams-web", response_class=HTMLResponse)
+@teams_web.post("/teams-web-con")
 def create_team(name: str = Form(...), db: Session = Depends(get_db)):
     """
     Endpoint called from within form for creating new team. Creates new team and returns all teams in database
@@ -59,4 +60,4 @@ def create_team(name: str = Form(...), db: Session = Depends(get_db)):
     team = crud.create_team(db, name)
     if team is None:
         print("something went wrong")
-    RedirectResponse("/teams-web")
+    return RedirectResponse(url=f"/teams-web", status_code=303)
diff --git a/server/sql_app/api/usb_logs_web.py b/server/sql_app/api/usb_logs_web.py
index 0559e59..cb83443 100644
--- a/server/sql_app/api/usb_logs_web.py
+++ b/server/sql_app/api/usb_logs_web.py
@@ -6,6 +6,7 @@ from sql_app import crud, models, schemas
 from ..database import SessionLocal, engine
 from fastapi import FastAPI, Request
 from fastapi.responses import HTMLResponse
+from fastapi_jwt_auth import AuthJWT
 from fastapi.staticfiles import StaticFiles
 from fastapi.templating import Jinja2Templates
 
@@ -28,10 +29,13 @@ def get_db():
 
 
 @usblogs_web.get("/logs-web", response_class=HTMLResponse)
-async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
+async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
+                    Authorize: AuthJWT = Depends()):
     """
     Returns template with all usb logs currently saved in database with its pcs, teams and licenses.
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
     logs = crud.get_logs(db, skip=skip, limit=limit)
     pcs = []
     for log in logs:
@@ -40,8 +44,10 @@ async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Sessi
     pc_obj = crud.find_pcs(db, pcs)
     teams = crud.get_teams(db, skip=skip, limit=limit)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
+    if current_user != "admin":
+        current_user = "guest"
     return templates.TemplateResponse("logs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
-                                                    "licenses": licenses})
+                                                    "licenses": licenses, "user": current_user})
 
 
 @usblogs_web.post("/logs-web", response_class=HTMLResponse)
diff --git a/server/sql_app/crud.py b/server/sql_app/crud.py
index eb3b7f8..cc20541 100644
--- a/server/sql_app/crud.py
+++ b/server/sql_app/crud.py
@@ -74,11 +74,48 @@ def create_license(db: Session, name: str, expdate: date):
 
 def get_license_devices(db: Session, license_id: int):
     """
-    returns all entries in devices_licenses table
+    returns all entries in devices_licenses table with given license_id
     """
     return db.query(models.DeviceLicense).filter(models.DeviceLicense.license_id == license_id).all()
 
 
+def get_device_licenses(db: Session, device_id: int):
+    """
+    returns all entries in devices_licenses table with given license_id
+    """
+    return db.query(models.DeviceLicense).filter(models.DeviceLicense.device_id == device_id).all()
+
+
+def get_devicelicense_by_devicelicense(db: Session, device_id: int, license_id: int):
+    """
+    returns entry in devices_licenses table with given device id and license id
+    """
+    return db.query(models.DeviceLicense).filter(and_(models.DeviceLicense.device_id == device_id,
+                                                      models.DeviceLicense.license_id == license_id)).first()
+
+
+def get_bodydevicelicense_by_bodydevicelicense(db: Session, device_id: int, license_id: int):
+    """
+    returns entry in bodydevices_licenses table with given body device id and license id
+    """
+    return db.query(models.BodyDeviceLicense).filter(and_(models.BodyDeviceLicense.bodydevice_id == device_id,
+                                                      models.BodyDeviceLicense.license_id == license_id)).first()
+
+
+def get_license_bodydevice(db: Session, license_id: int):
+    """
+    returns all entries in bodydevices_licenses with given license_id
+    """
+    return db.query(models.BodyDeviceLicense).filter(models.BodyDeviceLicense.license_id == license_id).all()
+
+
+def get_bodydevice_license(db: Session, device_id: int):
+    """
+    returns all entries in bodydevices_licenses with given license_id
+    """
+    return db.query(models.BodyDeviceLicense).filter(models.BodyDeviceLicense.bodydevice_id == device_id).all()
+
+
 def create_device_license(db: Session, device: int, license: int, time: datetime):
     """
     creates new entry in devices_licenses table with device id, license id and time.
@@ -91,6 +128,38 @@ def create_device_license(db: Session, device: int, license: int, time: datetime
     return db_device_license
 
 
+def delete_device_license(db: Session, device: int, license: int):
+    """
+    deletes entry in devices_licenses table with device id, license id and time.
+    """
+    db_device_license = get_devicelicense_by_devicelicense(db, device, license)
+    db_lic = db.delete(db_device_license)
+    db.commit()
+    return db_lic
+
+
+def delete_bodydevice_license(db: Session, device: int, license: int):
+    """
+    deletes entry in devices_licenses table with device id, license id and time.
+    """
+    db_device_license = get_bodydevicelicense_by_bodydevicelicense(db, device, license)
+    db_lic = db.delete(db_device_license)
+    db.commit()
+    return db_lic
+
+
+def create_body_device_license(db: Session, device: int, license: int, time: datetime):
+    """
+    creates new entry in devices_licenses table with device id, license id and time.
+    """
+    db_device_license = models.BodyDeviceLicense(bodydevice_id=device, license_id=license,
+                                                 assigned_datetime=time)
+    db.add(db_device_license)
+    db.commit()
+    db.refresh(db_device_license)
+    return db_device_license
+
+
 def find_pc_by_username(db: Session, name: str):
     """
     Finds one pc by given username
@@ -107,7 +176,7 @@ def get_pc(db: Session, pc_id: int):
 
 def update_pc(db: Session, pc_id: int, team: str):
     """
-    Function updates team of one specific pc
+    Updates team of one specific pc
     """
     old_pc = get_pc(db, pc_id)
     team = get_team(db, int(team))
@@ -274,7 +343,7 @@ def get_ld_logs(db: Session, skip: int = 0, limit: int = 100):
     """
     Returns all ld debugger logs in database
     """
-    return db.query(models.LDLog).offset(skip).limit(limit).all()
+    return db.query(models.LDLog).order_by(desc(models.LDLog.timestamp)).offset(skip).limit(limit).all()
 
 
 def create_ld_logs(db: Session, item: schemas.LDTempBase, head_id: int, body_id: int, pc_id: int, date: datetime):
@@ -309,37 +378,95 @@ def find_filtered_logs(db: Session, logs: []):
     return db.query(models.USBLog).filter(models.USBLog.id.in_(logs)).order_by(desc(models.USBLog.timestamp)).all()
 
 
+def find_filtered_ldlogs(db: Session, logs: []):
+    """
+    Returns all ld logs with ids in given id array.
+    """
+    return db.query(models.LDLog).filter(models.LDLog.id.in_(logs)).order_by(desc(models.LDLog.timestamp)).all()
+
+
+def get_filtered_ldlogs(db: Session, pc: str, tema: str, lic: str):
+    """
+    Function creates query string used for filtering by pc username, team name and license name.
+    Depending on selected filters assembles query string for database
+    """
+    execute_string = "SELECT * FROM ld_logs AS logs"
+    pcs = find_pc_by_username(db, pc)
+    if pc != "all":
+        if pcs is not None:
+            execute_string += "  WHERE logs.pc_id = " + str(pcs.id)
+    if tema != "all":
+        team = find_team(db, tema)
+        if team is not None:
+            pcst = get_pcs_by_team(db, team.id)
+            pc_ids = "("
+            for p in pcst:
+                pc_ids += str(p.id) + ", "
+            def_pc_ids = pc_ids[:-2] + ")"
+            if pc != "all" and pcs is not None:
+                if len(def_pc_ids) > 1:
+                    execute_string += " AND logs.pc_id IN " + def_pc_ids
+            else:
+                if len(def_pc_ids) > 1:
+                    execute_string += " WHERE logs.pc_id IN " + def_pc_ids
+    if lic != "all":
+        license = find_license(db, lic)
+        if license is not None:
+            device_licenses = get_license_bodydevice(db, license.id)
+            dev_ids = "("
+            for dev in device_licenses:
+                dev_ids += str(dev.bodydevice_id) + ", "
+            defin_ids = dev_ids[:-2] + ")"
+            if pc != "all" or tema != "all":
+                if len(defin_ids) > 1:
+                    execute_string += " AND logs.body_id IN " + defin_ids
+            else:
+                if len(defin_ids) > 1:
+                    execute_string += " WHERE logs.body_id IN " + defin_ids
+
+    # executing assembled query string
+    result = db.execute(execute_string)
+    return result
+
+
 def get_filtered_logs(db: Session, pc: str, tema: str, lic: str):
     """
     Function creates query string used for filtering by pc username, team name and license name.
     Depending on selected filters assembles query string for database
     """
     execute_string = "SELECT * FROM usb_logs AS logs"
+    pcs = find_pc_by_username(db, pc)
     if pc != "all":
-        pcs = find_pc_by_username(db, pc)
-        execute_string += "  WHERE logs.pc_id = " + str(pcs.id)
+        if pcs is not None:
+            execute_string += "  WHERE logs.pc_id = " + str(pcs.id)
     if tema != "all":
         team = find_team(db, tema)
-        pcs = get_pcs_by_team(db, team.id)
-        pc_ids = "("
-        for p in pcs:
-            pc_ids += str(p.id) + ", "
-        def_pc_ids = pc_ids[:-2] + ")"
-        if pc != "all":
-            execute_string += " AND logs.pc_id IN " + def_pc_ids
-        else:
-            execute_string += " WHERE logs.pc_id IN " + def_pc_ids
+        if team is not None:
+            pcst = get_pcs_by_team(db, team.id)
+            pc_ids = "("
+            for p in pcst:
+                pc_ids += str(p.id) + ", "
+            def_pc_ids = pc_ids[:-2] + ")"
+            if pc != "all" and pcs is not None:
+                if len(def_pc_ids) > 1:
+                    execute_string += " AND logs.pc_id IN " + def_pc_ids
+            else:
+                if len(def_pc_ids) > 1:
+                    execute_string += " WHERE logs.pc_id IN " + def_pc_ids
     if lic != "all":
         license = find_license(db, lic)
-        device_licenses = get_license_devices(db, license.id)
-        dev_ids = "("
-        for dev in device_licenses:
-            dev_ids += str(dev.device_id) + ", "
-        defin_ids = dev_ids[:-2] + ")"
-        if pc != "all" or tema != "all":
-            execute_string += " AND logs.device_id IN " + defin_ids
-        else:
-            execute_string += " WHERE logs.device_id IN " + defin_ids
+        if license is not None:
+            device_licenses = get_license_devices(db, license.id)
+            dev_ids = "("
+            for dev in device_licenses:
+                dev_ids += str(dev.device_id) + ", "
+            defin_ids = dev_ids[:-2] + ")"
+            if pc != "all" or tema != "all":
+                if len(defin_ids) > 1:
+                    execute_string += " AND logs.device_id IN " + defin_ids
+            else:
+                if len(defin_ids) > 1:
+                    execute_string += " WHERE logs.device_id IN " + defin_ids
 
     # executing assembled query string
     result = db.execute(execute_string)
diff --git a/server/sql_app/main.py b/server/sql_app/main.py
index 774d8eb..a77e626 100644
--- a/server/sql_app/main.py
+++ b/server/sql_app/main.py
@@ -10,6 +10,8 @@ from sql_app.api.usb_logs_web import usblogs_web
 from sql_app.api.teams import teams
 from sql_app.api.teams_web import teams_web
 from sql_app.api.auth import auth
+from sql_app.api.ld_logs_web import ldlogs_web
+from sql_app.api.bodydevices_web import body_device_web
 from fastapi import FastAPI
 
 
@@ -28,9 +30,11 @@ app.include_router(licenses_web)
 app.include_router(pcs_web)
 app.include_router(teams_web)
 app.include_router(usblogs_web)
+app.include_router(ldlogs_web)
+app.include_router(body_device_web)
 app.include_router(auth)
 
 '''
 if __name__ == "__main__":
-    uvicorn.run(app, host="192.168.0.22", port=8000)
+    uvicorn.run(app, host="192.168.176.1", port=8000)
 '''
diff --git a/server/sql_app/models.py b/server/sql_app/models.py
index 1040967..8d62fe9 100644
--- a/server/sql_app/models.py
+++ b/server/sql_app/models.py
@@ -52,7 +52,7 @@ class License(Base):
 
     # relationships for foreign keys, thus connecting table with devices table
     devices = relationship("DeviceLicense", back_populates="licenses")
-
+    body_devices = relationship("BodyDeviceLicense", back_populates="b_licenses")
 
 class DeviceLicense(Base):
     """
@@ -71,6 +71,23 @@ class DeviceLicense(Base):
     licenses = relationship("License", back_populates="devices")
 
 
+class BodyDeviceLicense(Base):
+    """
+    Class defining database table bodydevices_licenses
+    """
+    __tablename__ = "bodydevices_licenses"
+
+    id = Column(Integer, primary_key=True, index=True)
+    bodydevice_id = Column(Integer, ForeignKey("body_devices.id"))
+    license_id = Column(Integer, ForeignKey("licenses.id"))
+    assigned_datetime = Column(String, index=True, nullable=False)
+
+    # relationships for foreign keys, thus connecting table with devices and licenses
+    # tables
+    bodydevice_lic = relationship("BodyDevice", back_populates="debug_licenses")
+    b_licenses = relationship("License", back_populates="body_devices")
+
+
 class PC(Base):
     """
     Class defining database table pc
@@ -127,6 +144,7 @@ class BodyDevice(Base):
 
     # relationships for foreign keys, thus connecting table with ld_logs table
     b_logs = relationship("LDLog", back_populates="body_device")
+    debug_licenses = relationship("BodyDeviceLicense", back_populates="bodydevice_lic")
 
 
 class LDLog(Base):
diff --git a/server/templates/body-devices/body_device_license.html b/server/templates/body-devices/body_device_license.html
new file mode 100644
index 0000000..9c9dee5
--- /dev/null
+++ b/server/templates/body-devices/body_device_license.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Body Device License Connect</title>
+</head>
+<body>
+<h6><p>Vendor ID: {{device.vendor_id}}</p>
+    <p>Serial Number: {{device.serial_number}}</p>
+</h6>
+<form action="/body-devices-web/{{device.id}}" method="post">
+  <label for="lic">Licenses:</label>
+  <select id="lic" name="lic">
+      {% for license in licenses %}
+    <option value={{license.id}}>{{license.name}}</option>
+      {% endfor %}
+  </select>
+  <input type="submit" value="Connect">
+</form>
+<form action="/body-devices-web-del/{{device.id}}" method="post">
+  <label for="b_lic">Licenses:</label>
+  <select id="b_lic" name="b_lic">
+      {% for license in dev_lic %}
+    <option value={{license.id}}>{{license.name}}</option>
+      {% endfor %}
+  </select>
+  <input type="submit" value="Delete">
+</form>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/body-devices/body_devices.html b/server/templates/body-devices/body_devices.html
new file mode 100644
index 0000000..eb02d61
--- /dev/null
+++ b/server/templates/body-devices/body_devices.html
@@ -0,0 +1,72 @@
+<html>
+<head>
+    <title>Devices Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+</div>
+<h4>{{user}}</h4>
+<form action="/body-devices-web" method="post">
+    <label for="lic">License:</label>
+    <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
+    <datalist id="licenses">
+        {% for license in licenses %}
+        <option value="{{license.name}}"></option>
+        {% endfor %}
+    </datalist>
+  <input type="submit" value="Filter">
+</form>
+<table>
+    <TR>
+        <TH>ID</TH>
+        <TH>Serial Number</TH>
+        <TH>Licenses</TH>
+        <TH>Status</TH>
+    </TR>
+    {% for i in range(devs) %}
+    <TR>
+        <TD class="ID"><a href="/body-device-license/{{devices[i].id}}">{{devices[i].id}}</a></TD>
+        <TD class="Serial Number">{{devices[i].serial_number}}</TD>
+        <TD class="License">
+            {% for lic in devices[i].debug_licenses %}
+                {{lic.b_licenses.name}}<BR>
+            {% endfor %}
+        </TD>
+        <TD class="Status">{{statuses[i]}}</TD>
+    </TR>
+    {% endfor %}
+    <TR>
+        <TD class="ID"></TD>
+        <TD class="Serial Number"></TD>
+        <TD class="License">
+            <form action="/license-create" method="get">
+                <input type="submit" value="Add">
+            </form>
+        </TD>
+    </TR>
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/body-devices/body_devices_normal.html b/server/templates/body-devices/body_devices_normal.html
new file mode 100644
index 0000000..a2c3da2
--- /dev/null
+++ b/server/templates/body-devices/body_devices_normal.html
@@ -0,0 +1,63 @@
+<html>
+<head>
+    <title>Devices Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+</div>
+<h4>{{user}}</h4>
+<form action="/body-devices-web" method="post">
+    <label for="lic">License:</label>
+    <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
+    <datalist id="licenses">
+        {% for license in licenses %}
+        <option value="{{license.name}}"></option>
+        {% endfor %}
+    </datalist>
+  <input type="submit" value="Filter">
+</form>
+<table>
+    <TR>
+        <TH>ID</TH>
+        <TH>Serial Number</TH>
+        <TH>Licenses</TH>
+        <TH>Status</TH>
+    </TR>
+    {% for i in range(devs) %}
+    <TR>
+        <TD class="ID">{{devices[i].id}}</TD>
+        <TD class="Serial Number">{{devices[i].serial_number}}</TD>
+        <TD class="License">
+            {% for lic in devices[i].debug_licenses %}
+                {{lic.b_licenses.name}}<BR>
+            {% endfor %}
+        </TD>
+        <TD class="Status">{{statuses[i]}}</TD>
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/devices/devicelicense.html b/server/templates/devices/devicelicense.html
index f3780b1..b8f8833 100644
--- a/server/templates/devices/devicelicense.html
+++ b/server/templates/devices/devicelicense.html
@@ -18,5 +18,14 @@
   </select>
   <input type="submit" value="Connect">
 </form>
+<form action="/devices-web-del/{{device.id}}" method="post">
+  <label for="lic_del">Licenses:</label>
+  <select id="lic_del" name="lic_del">
+      {% for license in dev_lic %}
+    <option value={{license.id}}>{{license.name}}</option>
+      {% endfor %}
+  </select>
+  <input type="submit" value="Delete">
+</form>
 </body>
 </html>
\ No newline at end of file
diff --git a/server/templates/devices/devices.html b/server/templates/devices/devices.html
index c1abf2d..93dee09 100644
--- a/server/templates/devices/devices.html
+++ b/server/templates/devices/devices.html
@@ -9,7 +9,9 @@
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
       <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
       <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
   </select>
@@ -21,9 +23,12 @@
     <input type="submit" value="Login" />
 </form>
 </div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
+</div>
+<h4>{{user}}</h4>
 <form action="/devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
diff --git a/server/templates/devices/devices_normal.html b/server/templates/devices/devices_normal.html
index 18b21a4..a87c3b2 100644
--- a/server/templates/devices/devices_normal.html
+++ b/server/templates/devices/devices_normal.html
@@ -9,7 +9,9 @@
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
       <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
       <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
   </select>
@@ -21,9 +23,12 @@
     <input type="submit" value="Login" />
 </form>
 </div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
+</div>
+<h4>{{user}}</h4>
 <form action="/devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
diff --git a/server/templates/ld-logs/ldlogs.html b/server/templates/ld-logs/ldlogs.html
new file mode 100644
index 0000000..e6f6c27
--- /dev/null
+++ b/server/templates/ld-logs/ldlogs.html
@@ -0,0 +1,85 @@
+<html>
+<head>
+    <title> LD Logs Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+</div>
+<h4>{{user}}</h4>
+<form action="/ldlogs-web" method="post">
+  <label for="pc">PC:</label>
+  <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
+    <datalist id="pcs">
+        {% for pc in pcs %}
+        <option value="{{pc.username}}"></option>
+        {% endfor %}
+    </datalist>
+    <label for="team">Team:</label>
+  <input id="team" name="team" type="text" list="teams" value="" placeholder="all">
+    <datalist id="teams">
+        {% for team in teams %}
+        <option value="{{team.name}}"></option>
+        {% endfor %}
+    </datalist>
+    <label for="lic">License:</label>
+    <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
+    <datalist id="licenses">
+        {% for license in licenses %}
+        <option value="{{license.name}}"></option>
+        {% endfor %}
+    </datalist>
+  <input type="submit" value="Filter">
+</form>
+    <table>
+    <TR>
+        <TH>ID</TH>
+        <TH>PC Username</TH>
+        <TH>PC Hostname</TH>
+        <TH>Team</TH>
+        <TH>Timestamp</TH>
+        <TH>Status</TH>
+        <TH>Head Device Serial Number</TH>
+        <TH>Body Device Serial Number</TH>
+    </TR>
+    {% for log in logs %}
+    <TR>
+        <TD class="ID">{{log.id}}</TD>
+        <TD class="Username">{{log.ldpc.username}}</TD>
+        <TD class="Hostname">{{log.ldpc.hostname}}</TD>
+        {% if log.ldpc.team == None %}
+            <TD class="Team">NONE</TD>
+        {% else %}
+            <TD class="Team">{{log.ldpc.team.name}}</TD>
+        {% endif %}
+        <TD class="Timestamp">{{log.timestamp}}</TD>
+        <TD class="Status">{{log.status}}</TD>
+        <TD class="HeadDeviceSerialNumber">{{log.head_device.serial_number}}</TD>
+        <TD class="BodyDeviceSerialNumber">{{log.body_device.serial_number}}</TD>
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/licenses/licenses.html b/server/templates/licenses/licenses.html
index 8e5ab8e..d9faf97 100644
--- a/server/templates/licenses/licenses.html
+++ b/server/templates/licenses/licenses.html
@@ -9,7 +9,9 @@
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
       <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
       <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
   </select>
diff --git a/server/templates/pcs/pcs.html b/server/templates/pcs/pcs.html
index 6532f24..fa268a5 100644
--- a/server/templates/pcs/pcs.html
+++ b/server/templates/pcs/pcs.html
@@ -9,7 +9,9 @@
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
       <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
       <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
   </select>
@@ -21,9 +23,12 @@
     <input type="submit" value="Login" />
 </form>
 </div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
+</div>
+<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/pcs/pcs_normal.html b/server/templates/pcs/pcs_normal.html
index bee77d2..a17833a 100644
--- a/server/templates/pcs/pcs_normal.html
+++ b/server/templates/pcs/pcs_normal.html
@@ -9,7 +9,9 @@
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
       <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
       <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
   </select>
@@ -21,9 +23,12 @@
     <input type="submit" value="Login" />
 </form>
 </div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
+</div>
+<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/teams/team_create.html b/server/templates/teams/team_create.html
index 16dcc0a..28fb63d 100644
--- a/server/templates/teams/team_create.html
+++ b/server/templates/teams/team_create.html
@@ -5,7 +5,7 @@
     <title>Create a Team</title>
 </head>
 <body>
-<form action="/teams-web" method="post">
+<form action="/teams-web-con" method="post">
   <label for="name">Name:</label><br>
   <input type="text" id="name" name="name"><br><br>
   <input type="submit" value="Submit">
diff --git a/server/templates/teams/teams.html b/server/templates/teams/teams.html
index 77e5052..f9889f0 100644
--- a/server/templates/teams/teams.html
+++ b/server/templates/teams/teams.html
@@ -9,7 +9,9 @@
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
       <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
       <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
   </select>
@@ -21,9 +23,12 @@
     <input type="submit" value="Login" />
 </form>
 </div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
+</div>
+<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/teams/teams_normal.html b/server/templates/teams/teams_normal.html
index f1a5fc1..1e3c70c 100644
--- a/server/templates/teams/teams_normal.html
+++ b/server/templates/teams/teams_normal.html
@@ -9,7 +9,9 @@
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
       <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
       <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
   </select>
@@ -21,9 +23,12 @@
     <input type="submit" value="Login" />
 </form>
 </div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
+</div>
+<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/usb-logs/logs.html b/server/templates/usb-logs/logs.html
index 7e7e4be..dc83324 100644
--- a/server/templates/usb-logs/logs.html
+++ b/server/templates/usb-logs/logs.html
@@ -9,7 +9,9 @@
   <select id="view" name="view" onchange="this.form.action=this.value;">
       <option value=""></option>
       <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
       <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
   </select>
@@ -21,9 +23,12 @@
     <input type="submit" value="Login" />
 </form>
 </div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
+</div>
+<h4>{{user}}</h4>
 <form action="/logs-web" method="post">
   <label for="pc">PC:</label>
   <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
-- 
GitLab


From 5dc6d077ca29461d54a5e6778cc2e204c73b7621 Mon Sep 17 00:00:00 2001
From: Matej Zeman <zeman339@gmail.com>
Date: Mon, 9 May 2022 14:43:49 +0200
Subject: [PATCH 6/8] security fix for all endpoints. Added view for Licenses
 and html template on "/" with information about server endpoints.

---
 server/sql_app/api/auth.py                    |  2 +-
 server/sql_app/api/bodydevices_web.py         | 21 ++++++-
 server/sql_app/api/devices_web.py             | 21 ++++++-
 server/sql_app/api/licenses_web.py            | 41 ++++++++++---
 server/sql_app/api/pcs_web.py                 | 14 ++++-
 server/sql_app/api/teams_web.py               | 23 ++++++--
 server/sql_app/api/usb_logs_web.py            | 12 +++-
 server/sql_app/main.py                        |  2 +-
 server/templates/auth/login.html              |  4 +-
 .../templates/body-devices/body_devices.html  |  1 +
 .../body-devices/body_devices_normal.html     |  1 +
 server/templates/devices/devices.html         |  1 +
 server/templates/devices/devices_normal.html  |  1 +
 server/templates/ld-logs/ldlogs.html          |  1 +
 server/templates/licenses/license_create.html |  2 +-
 server/templates/licenses/licenses.html       |  7 +++
 .../templates/licenses/licenses_normal.html   | 48 +++++++++++++++
 server/templates/pcs/pcs.html                 |  1 +
 server/templates/pcs/pcs_normal.html          |  1 +
 server/templates/teams/teams.html             |  9 ++-
 server/templates/teams/teams_normal.html      |  7 +++
 server/templates/usb-logs/crossroad.html      | 59 +++++++++++++++++++
 server/templates/usb-logs/logs.html           |  1 +
 23 files changed, 250 insertions(+), 30 deletions(-)
 create mode 100644 server/templates/licenses/licenses_normal.html
 create mode 100644 server/templates/usb-logs/crossroad.html

diff --git a/server/sql_app/api/auth.py b/server/sql_app/api/auth.py
index 069d27c..f01ef83 100644
--- a/server/sql_app/api/auth.py
+++ b/server/sql_app/api/auth.py
@@ -1,6 +1,6 @@
 from fastapi import Depends, APIRouter, Form
 from fastapi import Request
-from fastapi.responses import HTMLResponse
+from fastapi.responses import HTMLResponse, RedirectResponse
 from fastapi.templating import Jinja2Templates
 from fastapi_jwt_auth import AuthJWT
 from pydantic import BaseModel
diff --git a/server/sql_app/api/bodydevices_web.py b/server/sql_app/api/bodydevices_web.py
index 9b13bb7..48b345e 100644
--- a/server/sql_app/api/bodydevices_web.py
+++ b/server/sql_app/api/bodydevices_web.py
@@ -87,10 +87,15 @@ async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic:
 
 
 @body_device_web.get("/body-device-license/{device_id}", response_class=HTMLResponse)
-async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db)):
+async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db),
+                          Authorize: AuthJWT = Depends()):
     """
     Returns template with one body device and all available licenses that can be assigned to it.
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     device = crud.get_body_device(db, device_id)
     dev_licenses = crud.get_bodydevice_license(db, device_id)
     lic_names = []
@@ -109,20 +114,30 @@ async def connect_dev_lic(request: Request, device_id: int, db: Session = Depend
 
 
 @body_device_web.post("/body-devices-web/{device_id}")
-async def connect_post(device_id: int, lic: str = Form(...), db: Session = Depends(get_db)):
+async def connect_post(device_id: int, lic: str = Form(...), db: Session = Depends(get_db),
+                       Authorize: AuthJWT = Depends()):
     """
     Endpoint called from template for connecting body device with license. Adds entry to bodydevices_licenses
     table and redirects to body-devices-web endpoint
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     crud.create_body_device_license(db, device_id, int(lic), datetime.now())
     return RedirectResponse(url=f"/body-devices-web", status_code=303)
 
 
 @body_device_web.post("/body-devices-web-del/{device_id}")
-async def delete_post(device_id: int, b_lic: str = Form(...), db: Session = Depends(get_db)):
+async def delete_post(device_id: int, b_lic: str = Form(...), db: Session = Depends(get_db),
+                      Authorize: AuthJWT = Depends()):
     """
     Endpoint called from template for connecting body device with license. Adds entry to devices_licenses
     table and redirects to body-devices-web endpoint
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     crud.delete_bodydevice_license(db, device_id, int(b_lic))
     return RedirectResponse(url=f"/body-devices-web", status_code=303)
\ No newline at end of file
diff --git a/server/sql_app/api/devices_web.py b/server/sql_app/api/devices_web.py
index 97c38a5..0d82a6b 100644
--- a/server/sql_app/api/devices_web.py
+++ b/server/sql_app/api/devices_web.py
@@ -87,10 +87,15 @@ async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic:
 
 
 @device_web.get("/device-license/{device_id}", response_class=HTMLResponse)
-async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db)):
+async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db),
+                          Authorize: AuthJWT = Depends()):
     """
     Returns template with one device and all available licenses that can be assigned to it.
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     device = crud.get_device(db, device_id)
     dev_licenses = crud.get_device_licenses(db, device_id)
     lic_names = []
@@ -109,20 +114,30 @@ async def connect_dev_lic(request: Request, device_id: int, db: Session = Depend
 
 
 @device_web.post("/devices-web/{device_id}")
-async def connect_post(device_id: int, lic: str = Form(...), db: Session = Depends(get_db)):
+async def connect_post(device_id: int, lic: str = Form(...), db: Session = Depends(get_db),
+                       Authorize: AuthJWT = Depends()):
     """
     Endpoint called from template for connecting device with license. Adds entry to devices_licenses
     table and redirects to devices-web endpoint
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     crud.create_device_license(db, device_id, int(lic), datetime.now())
     return RedirectResponse(url=f"/devices-web", status_code=303)
 
 
 @device_web.post("/devices-web-del/{device_id}")
-async def delete_post(device_id: int, lic_del: str = Form(...), db: Session = Depends(get_db)):
+async def delete_post(device_id: int, lic_del: str = Form(...), db: Session = Depends(get_db),
+                      Authorize: AuthJWT = Depends()):
     """
     Endpoint called from template for deleting device-license connection. Adds entry to bodydevices_licenses
     table and redirects to devices-web endpoint
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     crud.delete_device_license(db, device_id, int(lic_del))
     return RedirectResponse(url=f"/devices-web", status_code=303)
diff --git a/server/sql_app/api/licenses_web.py b/server/sql_app/api/licenses_web.py
index 24de037..f402a1b 100644
--- a/server/sql_app/api/licenses_web.py
+++ b/server/sql_app/api/licenses_web.py
@@ -7,6 +7,7 @@ from sql_app import crud, models, schemas
 from ..database import SessionLocal, engine
 from fastapi import FastAPI, Request
 from fastapi.responses import HTMLResponse, RedirectResponse
+from fastapi_jwt_auth import AuthJWT
 from fastapi.staticfiles import StaticFiles
 from fastapi.templating import Jinja2Templates
 
@@ -30,28 +31,50 @@ def get_db():
 
 
 @licenses_web.get("/license-create", response_class=HTMLResponse)
-async def licenses_create_web(request: Request):
+async def licenses_create_web(request: Request, Authorize: AuthJWT = Depends()):
     """
     Returns template with Form for creating new license.
     """
-    return templates.TemplateResponse("license_create.html", {"request": request})
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
+    return templates.TemplateResponse("license_create.html", {"request": request, "minimum_date": date.today()})
 
 
 @licenses_web.get("/licenses-web", response_class=HTMLResponse)
-async def read_licenses_web(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
+async def read_licenses_web(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
+                            Authorize: AuthJWT = Depends()):
     """
     Returns template with all licenses currently saved in database
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses})
-
+    if current_user == "admin":
+        return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses,
+                                                            "user": current_user})
+    else:
+        current_user = "guest"
+        return templates.TemplateResponse("licenses_normal.html", {"request": request, "licenses": licenses,
+                                                            "user": current_user})
 
 @licenses_web.post("/licenses-web")
-def create_license(name: str = Form(...), expdate: date = Form(...), db: Session = Depends(get_db)):
+def create_license(name: str = Form(...), expdate: date = Form(...), db: Session = Depends(get_db),
+                   Authorize: AuthJWT = Depends()):
     """
     Endpoint called from create license form. Creates new license and redirects to devices-web endpoint
     """
-    db_license = crud.create_license(db, name, expdate)
-    if db_license is None:
-        print("something went wrong")
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
+    licenses = crud.get_licenses(db, 0, 100)
+    licenses_names = []
+    for l in licenses:
+        licenses_names.append(l.name)
+    if name not in licenses_names:
+        db_license = crud.create_license(db, name, expdate)
+        if db_license is None:
+            print("something went wrong")
     return RedirectResponse(url=f"/devices-web", status_code=303)
diff --git a/server/sql_app/api/pcs_web.py b/server/sql_app/api/pcs_web.py
index 02303ab..2779e46 100644
--- a/server/sql_app/api/pcs_web.py
+++ b/server/sql_app/api/pcs_web.py
@@ -44,10 +44,15 @@ async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Sessio
 
 
 @pcs_web.get("/pc-team/{pc_id}", response_class=HTMLResponse)
-async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(get_db)):
+async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(get_db),
+                          Authorize: AuthJWT = Depends()):
     """
     Returns template with Form for connecting pc with team
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     pc = crud.get_pc(db, pc_id)
     teams = crud.get_teams(db, 0, 100)
     return templates.TemplateResponse("pcteam.html",
@@ -55,9 +60,14 @@ async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(ge
 
 
 @pcs_web.post("/pcs-web/{pc_id}")
-async def connect_post(pc_id: int, team: str = Form(...), db: Session = Depends(get_db)):
+async def connect_post(pc_id: int, team: str = Form(...), db: Session = Depends(get_db),
+                       Authorize: AuthJWT = Depends()):
     """
     Endpoint called from within form for connecting pc with team. Updates certain pc with new team.
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     old_pc = crud.update_pc(db, pc_id, team)
     return RedirectResponse(url=f"/pcs-web", status_code=303)
diff --git a/server/sql_app/api/teams_web.py b/server/sql_app/api/teams_web.py
index c1752a1..616c1c7 100644
--- a/server/sql_app/api/teams_web.py
+++ b/server/sql_app/api/teams_web.py
@@ -45,19 +45,32 @@ async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Se
 
 
 @teams_web.get("/team-create", response_class=HTMLResponse)
-async def team_create_web(request: Request):
+async def team_create_web(request: Request, Authorize: AuthJWT = Depends()):
     """
     Returns template with form for creating new team
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
     return templates.TemplateResponse("team_create.html", {"request": request})
 
 
 @teams_web.post("/teams-web-con")
-def create_team(name: str = Form(...), db: Session = Depends(get_db)):
+def create_team(name: str = Form(...), db: Session = Depends(get_db), Authorize: AuthJWT = Depends()):
     """
     Endpoint called from within form for creating new team. Creates new team and returns all teams in database
     """
-    team = crud.create_team(db, name)
-    if team is None:
-        print("something went wrong")
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
+    teams = crud.get_teams(db, 0, 100)
+    teams_names = []
+    for t in teams:
+        teams_names.append(t.name)
+    if name not in teams_names:
+        team = crud.create_team(db, name)
+        if team is None:
+            print("something went wrong")
     return RedirectResponse(url=f"/teams-web", status_code=303)
diff --git a/server/sql_app/api/usb_logs_web.py b/server/sql_app/api/usb_logs_web.py
index cb83443..a4f57d0 100644
--- a/server/sql_app/api/usb_logs_web.py
+++ b/server/sql_app/api/usb_logs_web.py
@@ -53,10 +53,12 @@ async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Sessi
 @usblogs_web.post("/logs-web", response_class=HTMLResponse)
 async def filter_logs(request: Request, pc: str = Form("all"), team: str = Form("all"), lic: str = Form("all"),
                       skip: int = 0, limit: int = 100,
-                      db: Session = Depends(get_db)):
+                      db: Session = Depends(get_db), Authorize: AuthJWT = Depends()):
     """
     Endpoint used for filtering usb logs by user given form inputs.
     """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
     log = crud.get_filtered_logs(db, pc, team, lic)
     logs_ids = []
     for l in log:
@@ -65,6 +67,12 @@ async def filter_logs(request: Request, pc: str = Form("all"), team: str = Form(
     pc_obj = crud.get_pcs(db, skip=skip, limit=limit)
     teams = crud.get_teams(db, skip=skip, limit=limit)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
+    if current_user != "admin":
+        current_user = "guest"
     return templates.TemplateResponse("logs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
-                                                    "licenses": licenses})
+                                                    "licenses": licenses, "user": current_user})
+
 
+@usblogs_web.get("/", response_class=HTMLResponse)
+async def crossroad(request: Request):
+    return templates.TemplateResponse("crossroad.html", {"request": request})
diff --git a/server/sql_app/main.py b/server/sql_app/main.py
index a77e626..99026c6 100644
--- a/server/sql_app/main.py
+++ b/server/sql_app/main.py
@@ -36,5 +36,5 @@ app.include_router(auth)
 
 '''
 if __name__ == "__main__":
-    uvicorn.run(app, host="192.168.176.1", port=8000)
+    uvicorn.run(app, host="192.168.0.22", port=8000)
 '''
diff --git a/server/templates/auth/login.html b/server/templates/auth/login.html
index 49fdcdf..0def994 100644
--- a/server/templates/auth/login.html
+++ b/server/templates/auth/login.html
@@ -8,8 +8,8 @@
 <form action="/login" method="post">
   <label for="username">Username:</label><br>
   <input type="text" id="username" name="username"><br><br>
-    <label for="password">Expiration Date</label>
-  <input type="text" id="password" name="password">
+    <label for="password">Password</label>
+  <input type="password" id="password" name="password">
   <input type="submit" value="Submit">
 </form>
 </body>
diff --git a/server/templates/body-devices/body_devices.html b/server/templates/body-devices/body_devices.html
index eb02d61..1116968 100644
--- a/server/templates/body-devices/body_devices.html
+++ b/server/templates/body-devices/body_devices.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
diff --git a/server/templates/body-devices/body_devices_normal.html b/server/templates/body-devices/body_devices_normal.html
index a2c3da2..d0ce81b 100644
--- a/server/templates/body-devices/body_devices_normal.html
+++ b/server/templates/body-devices/body_devices_normal.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
diff --git a/server/templates/devices/devices.html b/server/templates/devices/devices.html
index 93dee09..3685a70 100644
--- a/server/templates/devices/devices.html
+++ b/server/templates/devices/devices.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
diff --git a/server/templates/devices/devices_normal.html b/server/templates/devices/devices_normal.html
index a87c3b2..7b5d898 100644
--- a/server/templates/devices/devices_normal.html
+++ b/server/templates/devices/devices_normal.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
diff --git a/server/templates/ld-logs/ldlogs.html b/server/templates/ld-logs/ldlogs.html
index e6f6c27..a936ff4 100644
--- a/server/templates/ld-logs/ldlogs.html
+++ b/server/templates/ld-logs/ldlogs.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
diff --git a/server/templates/licenses/license_create.html b/server/templates/licenses/license_create.html
index 709fb52..861174a 100644
--- a/server/templates/licenses/license_create.html
+++ b/server/templates/licenses/license_create.html
@@ -9,7 +9,7 @@
   <label for="name">Name:</label><br>
   <input type="text" id="name" name="name"><br><br>
     <label for="expdate">Expiration Date</label>
-  <input type="date" id="expdate" name="expdate">
+  <input type="date" id="expdate" name="expdate" min={{minimum_date}}>
   <input type="submit" value="Submit">
 </form>
 </body>
diff --git a/server/templates/licenses/licenses.html b/server/templates/licenses/licenses.html
index d9faf97..e66abfe 100644
--- a/server/templates/licenses/licenses.html
+++ b/server/templates/licenses/licenses.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -23,9 +24,12 @@
     <input type="submit" value="Login" />
 </form>
 </div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
+</div>
+<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
@@ -40,5 +44,8 @@
     </TR>
     {% endfor %}
 </table>
+<form action="/license-create" method="get">
+    <input type="submit" value="Add">
+</form>
 </body>
 </html>
\ No newline at end of file
diff --git a/server/templates/licenses/licenses_normal.html b/server/templates/licenses/licenses_normal.html
new file mode 100644
index 0000000..7b5b644
--- /dev/null
+++ b/server/templates/licenses/licenses_normal.html
@@ -0,0 +1,48 @@
+<html>
+<head>
+    <title>Licenses Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+</div>
+<h4>{{user}}</h4>
+<table>
+    <TR>
+        <TH>ID</TH>
+        <TH>Name</TH>
+        <TH>Expiration Date</TH>
+    </TR>
+    {% for license in licenses %}
+    <TR>
+        <TD class="ID">{{license.id}}</TD>
+        <TD class="Vendor ID">{{license.name}}</TD>
+        <TD class="Product ID">{{license.expiration_date}}</TD>
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/pcs/pcs.html b/server/templates/pcs/pcs.html
index fa268a5..79f3156 100644
--- a/server/templates/pcs/pcs.html
+++ b/server/templates/pcs/pcs.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
diff --git a/server/templates/pcs/pcs_normal.html b/server/templates/pcs/pcs_normal.html
index a17833a..52d9085 100644
--- a/server/templates/pcs/pcs_normal.html
+++ b/server/templates/pcs/pcs_normal.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
diff --git a/server/templates/teams/teams.html b/server/templates/teams/teams.html
index f9889f0..546666b 100644
--- a/server/templates/teams/teams.html
+++ b/server/templates/teams/teams.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -33,11 +34,17 @@
     <TR>
         <TH>ID</TH>
         <TH>Name</TH>
+        <TH>Members</TH>
     </TR>
     {% for team in teams %}
     <TR>
         <TD class="ID">{{team.id}}</TD>
-        <TD class="Vendor ID">{{team.name}}</TD>
+        <TD class="Name">{{team.name}}</TD>
+        <TD class="Members">
+        {% for ppl in team.pcs %}
+            {{ppl.username}}<BR>
+        {% endfor %}
+        </TD>
     </TR>
     {% endfor %}
 </table>
diff --git a/server/templates/teams/teams_normal.html b/server/templates/teams/teams_normal.html
index 1e3c70c..50a7883 100644
--- a/server/templates/teams/teams_normal.html
+++ b/server/templates/teams/teams_normal.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -33,11 +34,17 @@
     <TR>
         <TH>ID</TH>
         <TH>Name</TH>
+        <TH>Members</TH>
     </TR>
     {% for team in teams %}
     <TR>
         <TD class="ID">{{team.id}}</TD>
         <TD class="Vendor ID">{{team.name}}</TD>
+        <TD class="Members">
+        {% for ppl in team.pcs %}
+            {{ppl.username}}<BR>
+        {% endfor %}
+        </TD>
     </TR>
     {% endfor %}
 </table>
diff --git a/server/templates/usb-logs/crossroad.html b/server/templates/usb-logs/crossroad.html
new file mode 100644
index 0000000..f553dc4
--- /dev/null
+++ b/server/templates/usb-logs/crossroad.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Crossroad</title>
+</head>
+<body>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+<h3>Available endpoints are accessible from selectBox above</h3>
+<h4>Endpoints are:</h4>
+<table>
+    <TR>
+        <TH>URL</TH>
+        <TH>Purpose</TH>
+    </TR>
+    <TR>
+        <TD class="URL">/logs-web</TD>
+        <TD class="Purpose">Shows all saves Keyman logs. User can filter through license, team and user</TD>
+    </TR>
+    <TR>
+        <TD class="URL">/ldlogs-web</TD>
+        <TD class="Purpose">Shows all saves LD debugger logs. User can filter through license, team and user</TD>
+    </TR>
+    <TR>
+        <TD class="URL">/devices-web</TD>
+        <TD class="Purpose">Shows all Keyman devices saved in database and its last state (connected, disconnected)</TD>
+    </TR>
+    <TR>
+        <TD class="URL">/body-devices-web</TD>
+        <TD class="Purpose">Shows all LD Body devices saved in database and its last state (connected, disconnected)</TD>
+    </TR>
+    <TR>
+        <TD class="URL">/teams-web</TD>
+        <TD class="Purpose">Shows all teams currently saved in database and its members</TD>
+    </TR>
+    <TR>
+        <TD class="URL">/pcs-web</TD>
+        <TD class="Purpose">Shows all PCS currently saved in database and its team</TD>
+    </TR>
+    <TR>
+        <TD class="URL">/licenses-web</TD>
+        <TD class="Purpose">Shows all Licenses currently saved in database and its expiration date</TD>
+    </TR>
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/usb-logs/logs.html b/server/templates/usb-logs/logs.html
index dc83324..e1d0a17 100644
--- a/server/templates/usb-logs/logs.html
+++ b/server/templates/usb-logs/logs.html
@@ -14,6 +14,7 @@
       <option value="/body-devices-web">Body Devices</option>
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
   </select>
   <input type="submit" value="OK">
 </form>
-- 
GitLab


From cbd239c6c463b12d81e19d33ee2a53bd68e64c40 Mon Sep 17 00:00:00 2001
From: Matej Zeman <zeman339@gmail.com>
Date: Mon, 9 May 2022 17:48:57 +0200
Subject: [PATCH 7/8] Added signup and users table in database. Passwords are
 hashed. Added view for changing users roles.

---
 server/requirements.txt                       |   4 +-
 server/sql_app/api/auth.py                    | 117 ++++++++++++++++--
 server/sql_app/api/ld_logs_web.py             |  20 ++-
 server/sql_app/api/usb_logs_web.py            |  18 ++-
 server/sql_app/api/users_web.py               |  59 +++++++++
 server/sql_app/crud.py                        |  46 ++++++-
 server/sql_app/main.py                        |   2 +
 server/sql_app/models.py                      |  11 ++
 server/sql_app/schemas.py                     |  19 +++
 server/templates/auth/login.html              |   4 +-
 server/templates/auth/signup.html             |  16 +++
 .../templates/body-devices/body_devices.html  |   6 +
 .../body-devices/body_devices_normal.html     |   5 +
 server/templates/devices/devices.html         |   6 +
 server/templates/devices/devices_normal.html  |   5 +
 server/templates/ld-logs/ldlogs.html          |   6 +
 server/templates/ld-logs/ldlogs_normal.html   |  91 ++++++++++++++
 server/templates/licenses/licenses.html       |   6 +
 .../templates/licenses/licenses_normal.html   |   5 +
 server/templates/pcs/pcs.html                 |   6 +
 server/templates/pcs/pcs_normal.html          |   5 +
 server/templates/teams/teams.html             |   6 +
 server/templates/teams/teams_normal.html      |   5 +
 server/templates/usb-logs/logs.html           |   6 +
 server/templates/usb-logs/logs_normal.html    |  91 ++++++++++++++
 server/templates/users/users.html             |  50 ++++++++
 26 files changed, 590 insertions(+), 25 deletions(-)
 create mode 100644 server/sql_app/api/users_web.py
 create mode 100644 server/templates/auth/signup.html
 create mode 100644 server/templates/ld-logs/ldlogs_normal.html
 create mode 100644 server/templates/usb-logs/logs_normal.html
 create mode 100644 server/templates/users/users.html

diff --git a/server/requirements.txt b/server/requirements.txt
index e70f09c..7d8e232 100644
--- a/server/requirements.txt
+++ b/server/requirements.txt
@@ -5,4 +5,6 @@ uvicorn==0.17.6
 psycopg2-binary==2.8.6
 jinja2==3.1.1
 python-multipart==0.0.5
-fastapi-jwt-auth==0.5.0
\ No newline at end of file
+fastapi-jwt-auth==0.5.0
+passlib==1.7.4
+bcrypt==3.2.2
\ No newline at end of file
diff --git a/server/sql_app/api/auth.py b/server/sql_app/api/auth.py
index f01ef83..cf8aeba 100644
--- a/server/sql_app/api/auth.py
+++ b/server/sql_app/api/auth.py
@@ -3,15 +3,29 @@ from fastapi import Request
 from fastapi.responses import HTMLResponse, RedirectResponse
 from fastapi.templating import Jinja2Templates
 from fastapi_jwt_auth import AuthJWT
+from sqlalchemy.orm import Session
+from sql_app import crud
+from passlib.context import CryptContext
 from pydantic import BaseModel
+from ..database import SessionLocal, engine
 
 # Path to html templates used in this file
 templates = Jinja2Templates(directory="templates/auth")
 
+pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
+
 # prefix used for all endpoints in this file
 auth = APIRouter(prefix="")
 
 
+# Dependency
+def get_db():
+    db = SessionLocal()
+    try:
+        yield db
+    finally:
+        db.close()
+
 
 class Settings(BaseModel):
     authjwt_secret_key: str = "secret"
@@ -25,6 +39,7 @@ class Settings(BaseModel):
 def get_config():
     return Settings()
 
+
 # admin username and password
 fake_users_db = {
     "admin": {
@@ -34,6 +49,72 @@ fake_users_db = {
 }
 
 
+def verify_password(plain_password, hashed_password):
+    return pwd_context.verify(plain_password, hashed_password)
+
+
+def get_hash_password(password):
+    return pwd_context.hash(password)
+
+
+def auth_user(db, username: str, password: str):
+    user = crud.find_user(db, username)
+    if not user:
+        return None
+    if not verify_password(password, user.password):
+        return None
+    return user
+
+
+@auth.get("/signup", response_class=HTMLResponse)
+async def signup_get(request: Request):
+    """
+    return html template for signup
+    """
+    return templates.TemplateResponse("signup.html", {"request": request})
+
+
+@auth.post("/signup", response_class=HTMLResponse)
+async def signup(username: str = Form(...), password: str = Form(...), db: Session = Depends(get_db)):
+    """
+    Endpoint called form signup template. Creates new user with role guest that can be changed by admin user
+    """
+    users = crud.get_users(db, 0, 100)
+    users_names = []
+    for u in users:
+        users_names.append(u.username)
+    if username not in users_names:
+        new_user = crud.create_user(db, username, get_hash_password(password), "guest")
+        if new_user is None:
+            print("something went wrong")
+        return """
+            <html>
+                <head>
+                    <title>Signup</title>
+                </head>
+                <body>
+                    <h1>Signed in</h1>
+                    <form action="/logs-web" method="get">
+                        <input type="submit" value="Back" />
+                    </form>
+                </body>
+            </html>
+            """
+    else:
+        return """
+                    <html>
+                        <head>
+                            <title>Signup</title>
+                        </head>
+                        <body>
+                            <h1>Username taken</h1>
+                            <form action="/logs-web" method="get">
+                                <input type="submit" value="Back" />
+                            </form>
+                        </body>
+                    </html>
+                    """
+
 @auth.get("/login", response_class=HTMLResponse)
 async def login_get(request: Request):
     """
@@ -43,22 +124,40 @@ async def login_get(request: Request):
 
 
 @auth.post("/login", response_class=HTMLResponse)
-async def login(username: str = Form(...), password: str = Form(...), Authorize: AuthJWT = Depends()):
+async def login(username: str = Form(...), password: str = Form(...), db: Session = Depends(get_db),
+                Authorize: AuthJWT = Depends()):
     """
     Endpoint called from login template. Checks if given username and password aligns with admin
     username and password and returns token for browser according to given username and password
     """
-    user_dict = fake_users_db.get(username)
-    if user_dict != None:
-        if user_dict["username"] == username and user_dict["password"] == password:
+    user = auth_user(db, username, password)
+    if user != None:
+        if user.role == "admin":
             access_token = Authorize.create_access_token(subject="admin", expires_time=False)
             refresh_token = Authorize.create_refresh_token(subject="admin", expires_time=False)
         else:
-            access_token = Authorize.create_access_token(subject="host", expires_time=False)
-            refresh_token = Authorize.create_refresh_token(subject="host", expires_time=False)
+            access_token = Authorize.create_access_token(subject="guest", expires_time=False)
+            refresh_token = Authorize.create_refresh_token(subject="guest", expires_time=False)
     else:
-        access_token = Authorize.create_access_token(subject="host", expires_time=False)
-        refresh_token = Authorize.create_refresh_token(subject="host", expires_time=False)
+        usr = fake_users_db.get(username)
+        if usr != None:
+            if usr["username"] == username and usr["password"] == password:
+                access_token = Authorize.create_access_token(subject="admin", expires_time=False)
+                refresh_token = Authorize.create_refresh_token(subject="admin", expires_time=False)
+        else:
+            return """
+                <html>
+                    <head>
+                        <title>Login</title>
+                    </head>
+                    <body>
+                        <h1>Wrong Username or Password</h1>
+                        <form action="/login" method="get">
+                            <input type="submit" value="Back" />
+                        </form>
+                    </body>
+                </html>
+                """
 
     # Set the JWT cookies in the response
     Authorize.set_access_cookies(access_token)
@@ -112,4 +211,4 @@ def logout(Authorize: AuthJWT = Depends()):
                 </form>
             </body>
         </html>
-        """
\ No newline at end of file
+        """
diff --git a/server/sql_app/api/ld_logs_web.py b/server/sql_app/api/ld_logs_web.py
index fbebfec..aef3733 100644
--- a/server/sql_app/api/ld_logs_web.py
+++ b/server/sql_app/api/ld_logs_web.py
@@ -44,10 +44,14 @@ async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Sessi
     pc_obj = crud.find_pcs(db, pcs)
     teams = crud.get_teams(db, skip=skip, limit=limit)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    if current_user != "admin":
+    if current_user == "admin":
+        return templates.TemplateResponse("ldlogs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                                          "licenses": licenses, "user": current_user})
+    else:
         current_user = "guest"
-    return templates.TemplateResponse("ldlogs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
-                                                      "licenses": licenses, "user": current_user})
+        return templates.TemplateResponse("ldlogs_normal.html",
+                                          {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                           "licenses": licenses, "user": current_user})
 
 
 @ldlogs_web.post("/ldlogs-web", response_class=HTMLResponse)
@@ -67,7 +71,11 @@ async def filter_logs(request: Request, pc: str = Form("all"), team: str = Form(
     pc_obj = crud.get_pcs(db, skip=skip, limit=limit)
     teams = crud.get_teams(db, skip=skip, limit=limit)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    if current_user != "admin":
+    if current_user == "admin":
+        return templates.TemplateResponse("ldlogs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                                          "licenses": licenses, "user": current_user})
+    else:
         current_user = "guest"
-    return templates.TemplateResponse("ldlogs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
-                                                      "licenses": licenses, "user": current_user})
+        return templates.TemplateResponse("ldlogs_normal.html",
+                                          {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                           "licenses": licenses, "user": current_user})
diff --git a/server/sql_app/api/usb_logs_web.py b/server/sql_app/api/usb_logs_web.py
index a4f57d0..75ebdc6 100644
--- a/server/sql_app/api/usb_logs_web.py
+++ b/server/sql_app/api/usb_logs_web.py
@@ -44,10 +44,13 @@ async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Sessi
     pc_obj = crud.find_pcs(db, pcs)
     teams = crud.get_teams(db, skip=skip, limit=limit)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    if current_user != "admin":
+    if current_user == "admin":
+        return templates.TemplateResponse("logs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                                        "licenses": licenses, "user": current_user})
+    else:
         current_user = "guest"
-    return templates.TemplateResponse("logs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
-                                                    "licenses": licenses, "user": current_user})
+        return templates.TemplateResponse("logs_normal.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                                        "licenses": licenses, "user": current_user})
 
 
 @usblogs_web.post("/logs-web", response_class=HTMLResponse)
@@ -67,10 +70,13 @@ async def filter_logs(request: Request, pc: str = Form("all"), team: str = Form(
     pc_obj = crud.get_pcs(db, skip=skip, limit=limit)
     teams = crud.get_teams(db, skip=skip, limit=limit)
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
-    if current_user != "admin":
+    if current_user == "admin":
+        return templates.TemplateResponse("logs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                                        "licenses": licenses, "user": current_user})
+    else:
         current_user = "guest"
-    return templates.TemplateResponse("logs.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
-                                                    "licenses": licenses, "user": current_user})
+        return templates.TemplateResponse("logs_normal.html", {"request": request, "logs": logs, "pcs": pc_obj, "teams": teams,
+                                                        "licenses": licenses, "user": current_user})
 
 
 @usblogs_web.get("/", response_class=HTMLResponse)
diff --git a/server/sql_app/api/users_web.py b/server/sql_app/api/users_web.py
new file mode 100644
index 0000000..523b22f
--- /dev/null
+++ b/server/sql_app/api/users_web.py
@@ -0,0 +1,59 @@
+from typing import List
+from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form
+from sqlalchemy.orm import Session
+from sql_app import crud, models, schemas
+from ..database import SessionLocal, engine
+from fastapi import FastAPI, Request
+from fastapi.responses import HTMLResponse, RedirectResponse
+from fastapi_jwt_auth import AuthJWT
+from fastapi.staticfiles import StaticFiles
+from fastapi.templating import Jinja2Templates
+
+models.Base.metadata.create_all(bind=engine)
+
+# Path to html templates used in this file
+templates = Jinja2Templates(directory="templates/users")
+
+# prefix used for all endpoints in this file
+users = APIRouter(prefix="")
+
+
+# Dependency
+def get_db():
+    db = SessionLocal()
+    try:
+        yield db
+    finally:
+        db.close()
+
+
+@users.get("/users-web", response_class=HTMLResponse)
+async def read_usrs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db),
+                   Authorize: AuthJWT = Depends()):
+    """
+    Returns template with all users currently saved in database
+    """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    users = crud.get_users(db, skip, limit)
+    if current_user == "admin":
+        return templates.TemplateResponse("users.html", {"request": request, "users": users})
+    else:
+        return RedirectResponse(url=f"/logs-web", status_code=303)
+
+
+@users.get("/user-role/{usr_id}", response_class=HTMLResponse)
+async def connect_pc_team(usr_id: int, db: Session = Depends(get_db), Authorize: AuthJWT = Depends()):
+    """
+    Changes role of user to either guest or admin depending on old role.
+    """
+    Authorize.jwt_optional()
+    current_user = Authorize.get_jwt_subject()
+    if current_user != "admin":
+        return RedirectResponse(url=f"/logs-web", status_code=303)
+    user = crud.find_user_byid(db, usr_id)
+    if user.role == "admin":
+        crud.change_role(db, usr_id, "guest")
+    else:
+        crud.change_role(db, usr_id, "admin")
+    return RedirectResponse(url=f"/users-web", status_code=303)
\ No newline at end of file
diff --git a/server/sql_app/crud.py b/server/sql_app/crud.py
index cc20541..f2b3a9b 100644
--- a/server/sql_app/crud.py
+++ b/server/sql_app/crud.py
@@ -99,7 +99,7 @@ def get_bodydevicelicense_by_bodydevicelicense(db: Session, device_id: int, lice
     returns entry in bodydevices_licenses table with given body device id and license id
     """
     return db.query(models.BodyDeviceLicense).filter(and_(models.BodyDeviceLicense.bodydevice_id == device_id,
-                                                      models.BodyDeviceLicense.license_id == license_id)).first()
+                                                          models.BodyDeviceLicense.license_id == license_id)).first()
 
 
 def get_license_bodydevice(db: Session, license_id: int):
@@ -188,6 +188,18 @@ def update_pc(db: Session, pc_id: int, team: str):
     db.refresh(old_pc)
     return old_pc
 
+def change_role(db: Session, usr_id: int, role: str):
+    """
+    Updates team of one specific pc
+    """
+    old_usr = find_user_byid(db, usr_id)
+    new = {'id': old_usr.id, 'username': old_usr.username, 'password': old_usr.password, 'role': role}
+    for key, value in new.items():
+        setattr(old_usr, key, value)
+    db.commit()
+    db.refresh(old_usr)
+    return old_usr
+
 
 def get_pcs(db: Session, skip: int = 0, limit: int = 100):
     """
@@ -482,3 +494,35 @@ def create_device_logs(db: Session, item: schemas.USBTempBase, dev_id: int, pc_i
     db.commit()
     db.refresh(db_log)
     return db_log
+
+
+def get_users(db: Session, skip: int = 0, limit: int = 100):
+    """
+    Returns all users saved in database
+    """
+    return db.query(models.User).offset(skip).limit(limit).all()
+
+
+def find_user(db: Session, name: str):
+    """
+    Finds one user by given username
+    """
+    return db.query(models.User).filter(models.User.username == name).first()
+
+
+def find_user_byid(db: Session, id: int):
+    """
+    Finds one user by given id
+    """
+    return db.query(models.User).filter(models.User.id == id).first()
+
+
+def create_user(db: Session, name: str, passw: str, rol: str):
+    """
+    Creates new user
+    """
+    db_user = models.User(username=name, password=passw, role=rol)
+    db.add(db_user)
+    db.commit()
+    db.refresh(db_user)
+    return db_user
diff --git a/server/sql_app/main.py b/server/sql_app/main.py
index 99026c6..224d136 100644
--- a/server/sql_app/main.py
+++ b/server/sql_app/main.py
@@ -12,6 +12,7 @@ from sql_app.api.teams_web import teams_web
 from sql_app.api.auth import auth
 from sql_app.api.ld_logs_web import ldlogs_web
 from sql_app.api.bodydevices_web import body_device_web
+from sql_app.api.users_web import users
 from fastapi import FastAPI
 
 
@@ -32,6 +33,7 @@ app.include_router(teams_web)
 app.include_router(usblogs_web)
 app.include_router(ldlogs_web)
 app.include_router(body_device_web)
+app.include_router(users)
 app.include_router(auth)
 
 '''
diff --git a/server/sql_app/models.py b/server/sql_app/models.py
index 8d62fe9..d91cfa5 100644
--- a/server/sql_app/models.py
+++ b/server/sql_app/models.py
@@ -165,3 +165,14 @@ class LDLog(Base):
     ldpc = relationship("PC", back_populates="ld_pc")
     head_device = relationship("HeadDevice", back_populates="h_logs")
     body_device = relationship("BodyDevice", back_populates="b_logs")
+
+class User(Base):
+    """
+    Class defining user in database with its own role
+    """
+    __tablename__ = "users"
+
+    id = Column(Integer, primary_key=True, index=True)
+    username = Column(String, index=True, nullable=False)
+    password = Column(String, index=True, nullable=False)
+    role = Column(String, index=True, nullable=False)
diff --git a/server/sql_app/schemas.py b/server/sql_app/schemas.py
index c0fe099..79becdc 100644
--- a/server/sql_app/schemas.py
+++ b/server/sql_app/schemas.py
@@ -232,3 +232,22 @@ class LDTemp(LDTempCreate):
 
     class Config:
         orm_mode = True
+
+
+class UserBase(BaseModel):
+    """
+    Classes used for creating new User entry
+    """
+    username: str
+    password: str
+    role: str
+
+class UserCreate(UserBase):
+    pass
+
+
+class User(UserCreate):
+    id: int
+
+    class Config:
+        orm_mode = True
diff --git a/server/templates/auth/login.html b/server/templates/auth/login.html
index 0def994..fa536c5 100644
--- a/server/templates/auth/login.html
+++ b/server/templates/auth/login.html
@@ -8,9 +8,9 @@
 <form action="/login" method="post">
   <label for="username">Username:</label><br>
   <input type="text" id="username" name="username"><br><br>
-    <label for="password">Password</label>
+    <label for="password">Password:</label>
   <input type="password" id="password" name="password">
-  <input type="submit" value="Submit">
+  <input type="submit" value="LogIn">
 </form>
 </body>
 </html>
\ No newline at end of file
diff --git a/server/templates/auth/signup.html b/server/templates/auth/signup.html
new file mode 100644
index 0000000..b8b19ff
--- /dev/null
+++ b/server/templates/auth/signup.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Sign Up</title>
+</head>
+<body>
+<form action="/signup" method="post">
+  <label for="username">Username:</label><br>
+  <input type="text" id="username" name="username"><br><br>
+    <label for="password">Password:</label>
+  <input type="password" id="password" name="password">
+  <input type="submit" value="Signup">
+</form>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/body-devices/body_devices.html b/server/templates/body-devices/body_devices.html
index 1116968..251afd4 100644
--- a/server/templates/body-devices/body_devices.html
+++ b/server/templates/body-devices/body_devices.html
@@ -15,6 +15,7 @@
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
       <option value="/licenses-web">Licenses</option>
+      <option value="/users-web">Users</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -25,6 +26,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/body-devices/body_devices_normal.html b/server/templates/body-devices/body_devices_normal.html
index d0ce81b..84db09c 100644
--- a/server/templates/body-devices/body_devices_normal.html
+++ b/server/templates/body-devices/body_devices_normal.html
@@ -25,6 +25,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/devices/devices.html b/server/templates/devices/devices.html
index 3685a70..7457c96 100644
--- a/server/templates/devices/devices.html
+++ b/server/templates/devices/devices.html
@@ -15,6 +15,7 @@
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
       <option value="/licenses-web">Licenses</option>
+      <option value="/users-web">Users</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -25,6 +26,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/devices/devices_normal.html b/server/templates/devices/devices_normal.html
index 7b5d898..fe35d04 100644
--- a/server/templates/devices/devices_normal.html
+++ b/server/templates/devices/devices_normal.html
@@ -25,6 +25,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/ld-logs/ldlogs.html b/server/templates/ld-logs/ldlogs.html
index a936ff4..d2793e1 100644
--- a/server/templates/ld-logs/ldlogs.html
+++ b/server/templates/ld-logs/ldlogs.html
@@ -15,6 +15,7 @@
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
       <option value="/licenses-web">Licenses</option>
+      <option value="/users-web">Users</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -25,6 +26,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/ld-logs/ldlogs_normal.html b/server/templates/ld-logs/ldlogs_normal.html
new file mode 100644
index 0000000..435b9f6
--- /dev/null
+++ b/server/templates/ld-logs/ldlogs_normal.html
@@ -0,0 +1,91 @@
+<html>
+<head>
+    <title> LD Logs Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+</div>
+<h4>{{user}}</h4>
+<form action="/ldlogs-web" method="post">
+  <label for="pc">PC:</label>
+  <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
+    <datalist id="pcs">
+        {% for pc in pcs %}
+        <option value="{{pc.username}}"></option>
+        {% endfor %}
+    </datalist>
+    <label for="team">Team:</label>
+  <input id="team" name="team" type="text" list="teams" value="" placeholder="all">
+    <datalist id="teams">
+        {% for team in teams %}
+        <option value="{{team.name}}"></option>
+        {% endfor %}
+    </datalist>
+    <label for="lic">License:</label>
+    <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
+    <datalist id="licenses">
+        {% for license in licenses %}
+        <option value="{{license.name}}"></option>
+        {% endfor %}
+    </datalist>
+  <input type="submit" value="Filter">
+</form>
+    <table>
+    <TR>
+        <TH>ID</TH>
+        <TH>PC Username</TH>
+        <TH>PC Hostname</TH>
+        <TH>Team</TH>
+        <TH>Timestamp</TH>
+        <TH>Status</TH>
+        <TH>Head Device Serial Number</TH>
+        <TH>Body Device Serial Number</TH>
+    </TR>
+    {% for log in logs %}
+    <TR>
+        <TD class="ID">{{log.id}}</TD>
+        <TD class="Username">{{log.ldpc.username}}</TD>
+        <TD class="Hostname">{{log.ldpc.hostname}}</TD>
+        {% if log.ldpc.team == None %}
+            <TD class="Team">NONE</TD>
+        {% else %}
+            <TD class="Team">{{log.ldpc.team.name}}</TD>
+        {% endif %}
+        <TD class="Timestamp">{{log.timestamp}}</TD>
+        <TD class="Status">{{log.status}}</TD>
+        <TD class="HeadDeviceSerialNumber">{{log.head_device.serial_number}}</TD>
+        <TD class="BodyDeviceSerialNumber">{{log.body_device.serial_number}}</TD>
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/licenses/licenses.html b/server/templates/licenses/licenses.html
index e66abfe..9b2471d 100644
--- a/server/templates/licenses/licenses.html
+++ b/server/templates/licenses/licenses.html
@@ -15,6 +15,7 @@
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
       <option value="/licenses-web">Licenses</option>
+      <option value="/users-web">Users</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -25,6 +26,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/licenses/licenses_normal.html b/server/templates/licenses/licenses_normal.html
index 7b5b644..7b672a1 100644
--- a/server/templates/licenses/licenses_normal.html
+++ b/server/templates/licenses/licenses_normal.html
@@ -25,6 +25,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/pcs/pcs.html b/server/templates/pcs/pcs.html
index 79f3156..f8897b7 100644
--- a/server/templates/pcs/pcs.html
+++ b/server/templates/pcs/pcs.html
@@ -15,6 +15,7 @@
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
       <option value="/licenses-web">Licenses</option>
+      <option value="/users-web">Users</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -25,6 +26,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/pcs/pcs_normal.html b/server/templates/pcs/pcs_normal.html
index 52d9085..3925ad0 100644
--- a/server/templates/pcs/pcs_normal.html
+++ b/server/templates/pcs/pcs_normal.html
@@ -25,6 +25,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/teams/teams.html b/server/templates/teams/teams.html
index 546666b..6dc7168 100644
--- a/server/templates/teams/teams.html
+++ b/server/templates/teams/teams.html
@@ -15,6 +15,7 @@
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
       <option value="/licenses-web">Licenses</option>
+      <option value="/users-web">Users</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -25,6 +26,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/teams/teams_normal.html b/server/templates/teams/teams_normal.html
index 50a7883..6e21020 100644
--- a/server/templates/teams/teams_normal.html
+++ b/server/templates/teams/teams_normal.html
@@ -25,6 +25,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/usb-logs/logs.html b/server/templates/usb-logs/logs.html
index e1d0a17..c69de25 100644
--- a/server/templates/usb-logs/logs.html
+++ b/server/templates/usb-logs/logs.html
@@ -15,6 +15,7 @@
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
       <option value="/licenses-web">Licenses</option>
+      <option value="/users-web">Users</option>
   </select>
   <input type="submit" value="OK">
 </form>
@@ -25,6 +26,11 @@
 </form>
 </div>
 <div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
 <form action="/logout" method="get">
     <input type="submit" value="Logout" />
 </form>
diff --git a/server/templates/usb-logs/logs_normal.html b/server/templates/usb-logs/logs_normal.html
new file mode 100644
index 0000000..1a7bf53
--- /dev/null
+++ b/server/templates/usb-logs/logs_normal.html
@@ -0,0 +1,91 @@
+<html>
+<head>
+    <title>Logs Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+</div>
+<h4>{{user}}</h4>
+<form action="/logs-web" method="post">
+  <label for="pc">PC:</label>
+  <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
+    <datalist id="pcs">
+        {% for pc in pcs %}
+        <option value="{{pc.username}}"></option>
+        {% endfor %}
+    </datalist>
+    <label for="team">Team:</label>
+  <input id="team" name="team" type="text" list="teams" value="" placeholder="all">
+    <datalist id="teams">
+        {% for team in teams %}
+        <option value="{{team.name}}"></option>
+        {% endfor %}
+    </datalist>
+    <label for="lic">License:</label>
+    <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
+    <datalist id="licenses">
+        {% for license in licenses %}
+        <option value="{{license.name}}"></option>
+        {% endfor %}
+    </datalist>
+  <input type="submit" value="Filter">
+</form>
+    <table>
+    <TR>
+        <TH>ID</TH>
+        <TH>PC Username</TH>
+        <TH>PC Hostname</TH>
+        <TH>Team</TH>
+        <TH>Timestamp</TH>
+        <TH>Status</TH>
+        <TH>Device Product ID</TH>
+        <TH>Device Serial Number</TH>
+    </TR>
+    {% for log in logs %}
+    <TR>
+        <TD class="ID">{{log.id}}</TD>
+        <TD class="Username">{{log.pc.username}}</TD>
+        <TD class="Hostname">{{log.pc.hostname}}</TD>
+        {% if log.pc.team == None %}
+            <TD class="Team">NONE</TD>
+        {% else %}
+            <TD class="Team">{{log.pc.team.name}}</TD>
+        {% endif %}
+        <TD class="Timestamp">{{log.timestamp}}</TD>
+        <TD class="Status">{{log.status}}</TD>
+        <TD class="DeviceProductID">{{log.device.product_id}}</TD>
+        <TD class="DeviceSerialNumber">{{log.device.serial_number}}</TD>
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/users/users.html b/server/templates/users/users.html
new file mode 100644
index 0000000..904942e
--- /dev/null
+++ b/server/templates/users/users.html
@@ -0,0 +1,50 @@
+<html>
+<head>
+    <title>Users Details</title>
+</head>
+<body>
+<div style='float:left'>
+<form action="" method="get">
+  <label for="view">Choose view:</label>
+  <select id="view" name="view" onchange="this.form.action=this.value;">
+      <option value=""></option>
+      <option value="/logs-web">Logs</option>
+      <option value="/ldlogs-web">LD Logs</option>
+      <option value="/devices-web">Devices</option>
+      <option value="/body-devices-web">Body Devices</option>
+      <option value="/teams-web">Teams</option>
+      <option value="/pcs-web">PCs</option>
+      <option value="/licenses-web">Licenses</option>
+  </select>
+  <input type="submit" value="OK">
+</form>
+</div>
+<div style='float:left'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
+<table>
+    <TR>
+        <TH>ID</TH>
+        <TH>Username</TH>
+        <TH>Role</TH>
+    </TR>
+    {% for user in users %}
+    <TR>
+        <TD class="ID"><a href="/user-role/{{user.id}}">{{user.id}}</a></TD>
+        <TD class="Username">{{user.username}}</TD>
+        <TD class="Role">{{user.role}}</TD>
+    </TR>
+    {% endfor %}
+</table>
+</body>
+</html>
\ No newline at end of file
-- 
GitLab


From 2552e6144a1c151f27867e95eba0d8062853fe99 Mon Sep 17 00:00:00 2001
From: Matej Zeman <zeman339@gmail.com>
Date: Mon, 9 May 2022 21:04:24 +0200
Subject: [PATCH 8/8] Changed certain template looks and controls.

---
 server/sql_app/api/auth.py                    | 17 ++++++----
 .../body-devices/body_device_license.html     |  2 +-
 .../templates/body-devices/body_devices.html  | 34 +++++++++----------
 .../body-devices/body_devices_normal.html     | 34 +++++++++----------
 server/templates/devices/devices.html         | 34 +++++++++----------
 server/templates/devices/devices_normal.html  | 34 +++++++++----------
 server/templates/ld-logs/ldlogs.html          | 34 +++++++++----------
 server/templates/ld-logs/ldlogs_normal.html   | 34 +++++++++----------
 server/templates/licenses/licenses.html       | 34 +++++++++----------
 .../templates/licenses/licenses_normal.html   | 34 +++++++++----------
 server/templates/pcs/pcs.html                 | 34 +++++++++----------
 server/templates/pcs/pcs_normal.html          | 34 +++++++++----------
 server/templates/teams/teams.html             | 34 +++++++++----------
 server/templates/teams/teams_normal.html      | 34 +++++++++----------
 server/templates/usb-logs/logs.html           | 34 +++++++++----------
 server/templates/usb-logs/logs_normal.html    | 34 +++++++++----------
 server/templates/users/users.html             | 29 ++++++++--------
 17 files changed, 249 insertions(+), 275 deletions(-)

diff --git a/server/sql_app/api/auth.py b/server/sql_app/api/auth.py
index cf8aeba..a66baca 100644
--- a/server/sql_app/api/auth.py
+++ b/server/sql_app/api/auth.py
@@ -93,9 +93,9 @@ async def signup(username: str = Form(...), password: str = Form(...), db: Sessi
                     <title>Signup</title>
                 </head>
                 <body>
-                    <h1>Signed in</h1>
+                    <h1>New user created. You can go back to previous page.</h1>
                     <form action="/logs-web" method="get">
-                        <input type="submit" value="Back" />
+                        <input type="submit" value="Home Page" />
                     </form>
                 </body>
             </html>
@@ -107,9 +107,9 @@ async def signup(username: str = Form(...), password: str = Form(...), db: Sessi
                             <title>Signup</title>
                         </head>
                         <body>
-                            <h1>Username taken</h1>
+                            <h1>Username taken. Try to choose different username.</h1>
                             <form action="/logs-web" method="get">
-                                <input type="submit" value="Back" />
+                                <input type="submit" value="Home Page" />
                             </form>
                         </body>
                     </html>
@@ -153,7 +153,10 @@ async def login(username: str = Form(...), password: str = Form(...), db: Sessio
                     <body>
                         <h1>Wrong Username or Password</h1>
                         <form action="/login" method="get">
-                            <input type="submit" value="Back" />
+                            <input type="submit" value="Log again" />
+                        </form>
+                        <form action="/login" method="get">
+                            <input type="submit" value="Home Page" />
                         </form>
                     </body>
                 </html>
@@ -168,9 +171,9 @@ async def login(username: str = Form(...), password: str = Form(...), db: Sessio
             <title>Login</title>
         </head>
         <body>
-            <h1>Logged in</h1>
+            <h1>Now you are logged in, you can continue to previous page.</h1>
             <form action="/logs-web" method="get">
-                <input type="submit" value="Back" />
+                <input type="submit" value="Home Page" />
             </form>
         </body>
     </html>
diff --git a/server/templates/body-devices/body_device_license.html b/server/templates/body-devices/body_device_license.html
index 9c9dee5..d0c1896 100644
--- a/server/templates/body-devices/body_device_license.html
+++ b/server/templates/body-devices/body_device_license.html
@@ -19,7 +19,7 @@
 </form>
 <form action="/body-devices-web-del/{{device.id}}" method="post">
   <label for="b_lic">Licenses:</label>
-  <select id="b_lic" name="b_lic">
+  <select id="b_lic" name="b_lic" >
       {% for license in dev_lic %}
     <option value={{license.id}}>{{license.name}}</option>
       {% endfor %}
diff --git a/server/templates/body-devices/body_devices.html b/server/templates/body-devices/body_devices.html
index 251afd4..b36a923 100644
--- a/server/templates/body-devices/body_devices.html
+++ b/server/templates/body-devices/body_devices.html
@@ -3,7 +3,22 @@
     <title>Devices Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -19,23 +34,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <form action="/body-devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
diff --git a/server/templates/body-devices/body_devices_normal.html b/server/templates/body-devices/body_devices_normal.html
index 84db09c..ece156d 100644
--- a/server/templates/body-devices/body_devices_normal.html
+++ b/server/templates/body-devices/body_devices_normal.html
@@ -3,7 +3,22 @@
     <title>Devices Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -18,23 +33,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <form action="/body-devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
diff --git a/server/templates/devices/devices.html b/server/templates/devices/devices.html
index 7457c96..e2f0bb7 100644
--- a/server/templates/devices/devices.html
+++ b/server/templates/devices/devices.html
@@ -3,7 +3,22 @@
     <title>Devices Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -19,23 +34,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <form action="/devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
diff --git a/server/templates/devices/devices_normal.html b/server/templates/devices/devices_normal.html
index fe35d04..4e0813f 100644
--- a/server/templates/devices/devices_normal.html
+++ b/server/templates/devices/devices_normal.html
@@ -3,7 +3,22 @@
     <title>Devices Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -18,23 +33,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <form action="/devices-web" method="post">
     <label for="lic">License:</label>
     <input id="lic" name="lic" type="text" list="licenses" value="" placeholder="all">
diff --git a/server/templates/ld-logs/ldlogs.html b/server/templates/ld-logs/ldlogs.html
index d2793e1..deda9b0 100644
--- a/server/templates/ld-logs/ldlogs.html
+++ b/server/templates/ld-logs/ldlogs.html
@@ -3,7 +3,22 @@
     <title> LD Logs Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -19,23 +34,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <form action="/ldlogs-web" method="post">
   <label for="pc">PC:</label>
   <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
diff --git a/server/templates/ld-logs/ldlogs_normal.html b/server/templates/ld-logs/ldlogs_normal.html
index 435b9f6..0487981 100644
--- a/server/templates/ld-logs/ldlogs_normal.html
+++ b/server/templates/ld-logs/ldlogs_normal.html
@@ -3,7 +3,22 @@
     <title> LD Logs Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -18,23 +33,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <form action="/ldlogs-web" method="post">
   <label for="pc">PC:</label>
   <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
diff --git a/server/templates/licenses/licenses.html b/server/templates/licenses/licenses.html
index 9b2471d..57a9b61 100644
--- a/server/templates/licenses/licenses.html
+++ b/server/templates/licenses/licenses.html
@@ -3,7 +3,22 @@
     <title>Licenses Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -19,23 +34,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/licenses/licenses_normal.html b/server/templates/licenses/licenses_normal.html
index 7b672a1..2f580d4 100644
--- a/server/templates/licenses/licenses_normal.html
+++ b/server/templates/licenses/licenses_normal.html
@@ -3,7 +3,22 @@
     <title>Licenses Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -18,23 +33,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/pcs/pcs.html b/server/templates/pcs/pcs.html
index f8897b7..72295e2 100644
--- a/server/templates/pcs/pcs.html
+++ b/server/templates/pcs/pcs.html
@@ -3,7 +3,22 @@
     <title>Pcs Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -19,23 +34,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/pcs/pcs_normal.html b/server/templates/pcs/pcs_normal.html
index 3925ad0..b6b6cd5 100644
--- a/server/templates/pcs/pcs_normal.html
+++ b/server/templates/pcs/pcs_normal.html
@@ -3,7 +3,22 @@
     <title>Pcs Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -18,23 +33,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/teams/teams.html b/server/templates/teams/teams.html
index 6dc7168..f6945e6 100644
--- a/server/templates/teams/teams.html
+++ b/server/templates/teams/teams.html
@@ -3,7 +3,22 @@
     <title>Teams Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -19,23 +34,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/teams/teams_normal.html b/server/templates/teams/teams_normal.html
index 6e21020..d25b5b9 100644
--- a/server/templates/teams/teams_normal.html
+++ b/server/templates/teams/teams_normal.html
@@ -3,7 +3,22 @@
     <title>Teams Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -18,23 +33,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <table>
     <TR>
         <TH>ID</TH>
diff --git a/server/templates/usb-logs/logs.html b/server/templates/usb-logs/logs.html
index c69de25..4f1bb07 100644
--- a/server/templates/usb-logs/logs.html
+++ b/server/templates/usb-logs/logs.html
@@ -3,7 +3,22 @@
     <title>Logs Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -19,23 +34,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <form action="/logs-web" method="post">
   <label for="pc">PC:</label>
   <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
diff --git a/server/templates/usb-logs/logs_normal.html b/server/templates/usb-logs/logs_normal.html
index 1a7bf53..aaf52e8 100644
--- a/server/templates/usb-logs/logs_normal.html
+++ b/server/templates/usb-logs/logs_normal.html
@@ -3,7 +3,22 @@
     <title>Logs Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:20px'>
+<b>Your role: {{user}}</b>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -18,23 +33,6 @@
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
-</div>
-<h4>{{user}}</h4>
 <form action="/logs-web" method="post">
   <label for="pc">PC:</label>
   <input id="pc" name="pc" type="text" list="pcs" value="" placeholder="all">
diff --git a/server/templates/users/users.html b/server/templates/users/users.html
index 904942e..dfb9e87 100644
--- a/server/templates/users/users.html
+++ b/server/templates/users/users.html
@@ -3,7 +3,19 @@
     <title>Users Details</title>
 </head>
 <body>
-<div style='float:left'>
+<div style='float:left;padding-right:5px'>
+<form action="/login" method="get">
+    <input type="submit" value="Login" />
+</form>
+</div>
+<div style='float:left;padding-right:5px'>
+<form action="/signup" method="get">
+    <input type="submit" value="Sign Up" />
+</form>
+</div>
+<form action="/logout" method="get">
+    <input type="submit" value="Logout" />
+</form>
 <form action="" method="get">
   <label for="view">Choose view:</label>
   <select id="view" name="view" onchange="this.form.action=this.value;">
@@ -15,23 +27,10 @@
       <option value="/teams-web">Teams</option>
       <option value="/pcs-web">PCs</option>
       <option value="/licenses-web">Licenses</option>
+      <option value="/users-web">Users</option>
   </select>
   <input type="submit" value="OK">
 </form>
-</div>
-<div style='float:left'>
-<form action="/login" method="get">
-    <input type="submit" value="Login" />
-</form>
-</div>
-<div style='float:left'>
-<form action="/signup" method="get">
-    <input type="submit" value="Sign Up" />
-</form>
-</div>
-<form action="/logout" method="get">
-    <input type="submit" value="Logout" />
-</form>
 <table>
     <TR>
         <TH>ID</TH>
-- 
GitLab