First Commit: Server Runs an Login works

main
Samuel Zielke 2 years ago
commit e1d80eacfe

3
.gitignore vendored

@ -0,0 +1,3 @@
venv/
*__pycache__/
*migrations/

Binary file not shown.

@ -0,0 +1,16 @@
"""
ASGI config for ecc project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecc.settings')
application = get_asgi_application()

@ -0,0 +1,130 @@
"""
Django settings for ecc project.
Generated by 'django-admin startproject' using Django 5.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-+_9h=k*n!a)p+il83lt)2ham5_u+8n)zz34^$x)3&hh7b78_(g'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# My created Apps
'login',
'main',
'leitstelle',
'monitor',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'ecc.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'ecc.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

@ -0,0 +1,29 @@
"""
URL configuration for ecc project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from .views import logout_view
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path("main/", include(("main.urls", 'main'), namespace='main')),
path('login/', include(('login.urls', 'login'), namespace='login')),
path('monitor/', include(('monitor.urls', 'login'), namespace='monitor')),
path('leitstelle/', include(('leitstelle.urls', 'login'), namespace='leitstelle')),
path("logout/", logout_view),
# path('', include('login.urls')),
]

@ -0,0 +1,7 @@
from django.shortcuts import redirect
from django.urls import reverse
from django.contrib.auth import logout
def logout_view(request):
logout(request)
return redirect(reverse('login:login'))

@ -0,0 +1,16 @@
"""
WSGI config for ecc project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecc.settings')
application = get_wsgi_application()

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

@ -0,0 +1,6 @@
from django.apps import AppConfig
class LeitstelleConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'leitstelle'

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

@ -0,0 +1,32 @@
{% load static %}
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<!-- all infos about iphone app -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="JW-ServiceTracker">
<link rel="apple-touch-icon" sizes="167x167" href="{% static 'img/clock.png' %}">
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'img/clock.png' %}">
<!-- all others -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<title>EmergencyControlCenter - Index</title>
</head>
<body>
{% block pushup %}
{% endblock %}
{% include "main/header.html" %}
{% block content %}
{% endblock %}
</div>
<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
</body>
</html>

@ -0,0 +1,17 @@
{% extends 'main/base.html' %}
{% block content %}
<div class="container-fluid row justify-content-center" style="padding: 4rem; margin-top: 5rem;">
<a href="#" class="col-3 row text-center" style="height: 15vh; align-items: center; border-radius: 1rem; box-shadow: 0rem 0rem 2rem rgb(97, 97, 97);">
<h3>Alarmierung<br>erstellen</h4>
</a>
<!-- <div class="col-1"></div>
<a href="#" class="col-4 row" style="height: 15vh; align-items: center; border-radius: 1rem; box-shadow: 0rem 0rem 2rem rgb(97, 97, 97);">
<span class="col-5 material-symbols-outlined" style="font-size: 7rem;">dashboard</span>
<h4 class="col-5 offset-1">Leitstelle</h4>
</a> -->
</div>
{% endblock %}

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="leitstelle"),
]

@ -0,0 +1,5 @@
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'leitstelle/index.html')

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

@ -0,0 +1,6 @@
from django.apps import AppConfig
class LoginConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'login'

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="ECC">
<title>Login</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</head>
<body class="text-center">
<form class="form-signin" method="post">
<p style="font-size: 2.75rem;"><c style="color: rgb(200, 69, 69)">Emergency</c><b></b></p>
<p style="font-size: 1.75rem; margin-top: -2rem;"><b>Control Center</b></p>
{% csrf_token %}
<input id="inputEmail" name="inputEmail" class="form-control" placeholder="username" required="" autofocus="" type="text">
<input id="inputPassword" name="inputPassword" class="form-control" placeholder="password" required="" type="password" style="margin:1rem 0; border-radius: .375rem;">
<p class="text-danger">{{ state }}</p>
<button class="btn btn-lg btn-block" style="background-color: rgb(200, 69, 69); color: white;" name="login" type="submit">Login</button>
</form>
</body>
</html>
<style>
html,
body {
height: 100%;
}
body {
display: -ms-flexbox;
display: -webkit-box;
display: flex;
-ms-flex-align: center;
-ms-flex-pack: center;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: center;
justify-content: center;
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .checkbox {
font-weight: 400;
}
.form-signin .form-control {
position: relative;
box-sizing: border-box;
height: auto;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
</style>

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,8 @@
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="login"),
path("logout", views.index, name="login"),
]

@ -0,0 +1,22 @@
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from django.urls import reverse
def index(request):
state = ""
if request.user.is_authenticated:
return redirect(reverse('main:index'))
else:
if request.method == "POST":
if not request.POST.get("login") == None:
username = request.POST.get("inputEmail")
password = request.POST.get("inputPassword")
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return redirect(reverse('main:index'))
else:
state = "Fehler bei der Anmeldung!"
return render(request, 'login/login.html', {'state':state})
return render(request, 'login/login.html')

@ -0,0 +1,9 @@
from django.contrib import admin
from .models import hours
# Register your models here.
class HoursAdmin(admin.ModelAdmin):
list_display = ("user", "date", "hours", "minutes", "is_ldc", "is_geplant")
admin.site.register(hours, HoursAdmin)

@ -0,0 +1,6 @@
from django.apps import AppConfig
class MainConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'main'

@ -0,0 +1,11 @@
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class hours(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
date = models.DateField(auto_now_add=False)
is_ldc = models.BooleanField(default=False)
is_geplant = models.BooleanField(default=False)
hours = models.IntegerField(auto_created=False, default=0)
minutes = models.IntegerField(auto_created=False, default=0)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,28 @@
/*font family from google fonts*/
@import url("https://fonts.googleapis.com/css2?family=Oswald:wght@300;400&display=swap");
html {
font-size: 62.5%; /*62.5% = 10px; to make it easier to calculate REM units.*/
}
body {
text-align: center;
font-family: "Oswald", sans-serif;
font-weight: 300;
font-size: 2.2rem;
display: flex;
justify-content: center;
align-items: center;
background-color: #faedcd;
height: 100vh;
}
#clock {max-width: 600px;}
/* for smaller screens below 700px */
@media only screen and (max-width: 700px) {
body {font-size: 1.8rem;}
}
/*for smaller screens below 300px*/
@media only screen and (max-width: 300px) {
body {font-size: 1.6rem;}
}

@ -0,0 +1,36 @@
/* GLOBAL */
a {
text-decoration: none;
color: black;
}
a:hover {
transition-duration: 0.25s;
/* box-shadow: 0rem 0rem 2rem rgb(200, 69, 69); */
color: rgb(200, 69, 69);
}
.container {
margin-top: 2rem;
margin-bottom: -2rem;
height: 100vh;
}
span.curser {
cursor:pointer;
}
img.pb {
max-width: 2rem;
height: auto;
}
.form-control-clear {
z-index: 10;
pointer-events: auto;
cursor: pointer;
}
.form-control {
height: 2.5rem;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because one or more lines are too long

@ -0,0 +1,58 @@
window.addEventListener("load", () => {
clock();
function clock() {
const today = new Date();
// get time components
const hours = today.getHours();
const minutes = today.getMinutes();
const seconds = today.getSeconds();
//add '0' to hour, minute & second when they are less 10
const hour = hours < 10 ? "0" + hours : hours;
const minute = minutes < 10 ? "0" + minutes : minutes;
const second = seconds < 10 ? "0" + seconds : seconds;
//make clock a 12-hour time clock
const hourTime = hour;
// if (hour === 0) {
// hour = 12;
// }
//assigning 'am' or 'pm' to indicate time of the day
// const ampm = hour < 12 ? "AM" : "PM";
// get date components
const month = today.getMonth();
const year = today.getFullYear();
const day = today.getDate();
//declaring a list of all months in a year
const monthList = [
"Janu",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
//get current date and time
const date = monthList[month] + " " + day + ", " + year;
// const time = hourTime + ":" + minute + ":" + second + ampm;
const time = hourTime + ":" + minute + ":" + second;
//combine current date and time
const dateTime = time;
//print current date and time to the DOM
document.getElementById("date-time").innerHTML = dateTime;
setTimeout(clock, 1000);
}
});

@ -0,0 +1,32 @@
{% load static %}
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<!-- all infos about iphone app -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="JW-ServiceTracker">
<link rel="apple-touch-icon" sizes="167x167" href="{% static 'img/clock.png' %}">
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'img/clock.png' %}">
<!-- all others -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<title>EmergencyControlCenter - Index</title>
</head>
<body>
{% block pushup %}
{% endblock %}
{% include "main/header.html" %}
{% block content %}
{% endblock %}
</div>
<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
</body>
</html>

@ -0,0 +1,27 @@
{% load static %}
<div class="container">
<div class="top_line row justify-content-between">
<div class="title col-6 text-start dropdown">
<span class="curser" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">
<!-- <h4><c style="color: rgb(168, 168, 168); vertical-align: top;" id="dropdownMenuLink" data-bs-toggle="dropdown"><c style="color: rgb(200, 69, 69)">Emergency</c>ControlCenter</h4> -->
<h4><c style="color: rgb(168, 168, 168); vertical-align: top;"><c style="color: rgb(200, 69, 69)">Emergency</c>ControlCenter</h4>
</span>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<!-- <li><a class="dropdown-item {% if menu == 1 %}active{% endif %}" href="/main/">Dashboard</a></li> -->
<li><a class="dropdown-item {% if menu == 2 %}active{% endif %}" href="/main/">Ansicht schließen</a></li>
</ul>
</div>
<div class="col-3 text-end dropdown">
<span class="curser" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">
<img class="pb" src="{% static 'img/user.png' %}" alt="User">
</span>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
{% if request.user.is_staff %}
<li><a class="dropdown-item" href="/admin">Admin-Seite</a></li>
{% endif %}
<li><a class="dropdown-item" href="/logout">Logout</a></li>
</ul>
</div>
</div>

@ -0,0 +1,18 @@
{% extends 'main/base.html' %}
{% block content %}
<div class="container-fluid row" style="padding: 4rem; margin-top: 5rem;">
<a href="/monitor/" class="col-4 offset-2 row" style="height: 15vh; align-items: center; border-radius: 1rem; box-shadow: 0rem 0rem 2rem rgb(97, 97, 97);">
<span class="col-5 material-symbols-outlined" style="font-size: 7rem;">tv</span>
<h4 class="col-5 offset-1">Monitor</h4>
</a>
<div class="col-1"></div>
<a href="/leitstelle/" class="col-4 row" style="height: 15vh; align-items: center; border-radius: 1rem; box-shadow: 0rem 0rem 2rem rgb(97, 97, 97);">
<span class="col-5 material-symbols-outlined" style="font-size: 7rem;">dashboard</span>
<h4 class="col-5 offset-1">Leitstelle</h4>
</a>
</div>
{% endblock %}

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index")
]

@ -0,0 +1,5 @@
from django.shortcuts import render, redirect
#INDEX
def index(request):
return render(request, 'main/index.html')

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecc.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

@ -0,0 +1,6 @@
from django.apps import AppConfig
class MonitorConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'monitor'

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

@ -0,0 +1,33 @@
{% load static %}
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<!-- all infos about iphone app -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="JW-ServiceTracker">
<link rel="apple-touch-icon" sizes="167x167" href="{% static 'img/clock.png' %}">
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'img/clock.png' %}">
<!-- all others -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<link rel="stylesheet" href="{% static 'css/clock.css' %}">
<title>EmergencyControlCenter - Index</title>
</head>
<body>
{% block pushup %}
{% endblock %}
{% include "main/header.html" %}
{% block content %}
{% endblock %}
</div>
<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
</body>
</html>

@ -0,0 +1,15 @@
{% extends 'main/base.html' %}
{% load static %}
{% block content %}
<div class="container-fluid row justify-content-start" style="padding: 0rem; margin-top: 2rem;" onload="startTime()">
<div class="col-4 text-center row" style="height: 15vh; align-items: center; border-radius: 1rem; box-shadow: 0rem 0rem 2rem rgb(97, 97, 97);">
<h1 id="date-time" style="font-size: 4rem;"></h1>
</div>
</div>
<script src="{% static 'js/clock.js' %}" type="text/javascript"></script>
{% endblock %}

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="monitor"),
]

@ -0,0 +1,5 @@
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'monitor/index.html')
Loading…
Cancel
Save

Powered by TurnKey Linux.