From 7e9059a9aa2d9a2d6ba356021c03990ea4648d2d Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Mon, 24 Nov 2025 10:37:23 +0100 Subject: [PATCH] feat: implement user authentication with login/logout functionality - Add user login screen with German interface - Add user icon and dropdown menu in header for authenticated users - Add password change functionality with proper redirects - Configure authentication URLs and settings - Ensure all auth functions redirect to main page instead of admin - Complete openspec change proposal for login feature --- VorgabenUI/settings.py | 5 ++ VorgabenUI/urls.py | 6 ++ openspec/changes/add-login/tasks.md | 5 ++ openspec/project.md | 63 +++++++++++++++++++ pages/templates/base.html | 24 +++++++ pages/templates/registration/login.html | 43 +++++++++++++ .../registration/password_change.html | 56 +++++++++++++++++ .../registration/password_change_done.html | 24 +++++++ 8 files changed, 226 insertions(+) create mode 100644 openspec/changes/add-login/tasks.md create mode 100644 openspec/project.md create mode 100644 pages/templates/registration/login.html create mode 100644 pages/templates/registration/password_change.html create mode 100644 pages/templates/registration/password_change_done.html diff --git a/VorgabenUI/settings.py b/VorgabenUI/settings.py index 80cc333..f32e2f8 100644 --- a/VorgabenUI/settings.py +++ b/VorgabenUI/settings.py @@ -152,6 +152,11 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DATA_UPLOAD_MAX_NUMBER_FIELDS=10250 NESTED_ADMIN_LAZY_INLINES = True +# Authentication settings +LOGIN_URL = 'login' +LOGIN_REDIRECT_URL = '/' +LOGOUT_REDIRECT_URL = 'login' + #LOGGING = { # "version": 1, # "handlers" :{ diff --git a/VorgabenUI/urls.py b/VorgabenUI/urls.py index d072398..5c568c7 100644 --- a/VorgabenUI/urls.py +++ b/VorgabenUI/urls.py @@ -18,6 +18,7 @@ from django.contrib import admin from django.urls import include, path, re_path from django.conf import settings from django.conf.urls.static import static +from django.contrib.auth import views as auth_views import dokumente.views import pages.views import referenzen.views @@ -32,6 +33,11 @@ urlpatterns = [ path('stichworte/', include("stichworte.urls")), path('referenzen/', referenzen.views.tree, name="referenz_tree"), path('referenzen//', referenzen.views.detail, name="referenz_detail"), + # Authentication URLs + path('login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'), + path('logout/', auth_views.LogoutView.as_view(next_page='/'), name='logout'), + path('password_change/', auth_views.PasswordChangeView.as_view(template_name='registration/password_change.html', success_url='/'), name='password_change'), + path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(template_name='registration/password_change_done.html'), name='password_change_done'), ] # Serve static files diff --git a/openspec/changes/add-login/tasks.md b/openspec/changes/add-login/tasks.md new file mode 100644 index 0000000..e554e71 --- /dev/null +++ b/openspec/changes/add-login/tasks.md @@ -0,0 +1,5 @@ +## 1. Add user login functionality +- [x] add a login screen for users +- [x] add an icon for logged in user on the top right corner of all page +- [x] add a menu to log out and change password on the user icon +- [x] all functions should go back to the main page, not the django admin page diff --git a/openspec/project.md b/openspec/project.md new file mode 100644 index 0000000..50ff634 --- /dev/null +++ b/openspec/project.md @@ -0,0 +1,63 @@ +# Project Context + +## Purpose +This is a Django-based document management system for regulatory documents (Dokumente) and their provisions (Vorgaben). It manages validity periods, conflicts between overlapping provisions, references, keywords, and roles. The system supports importing documents, checking for compliance, and maintaining changelogs. + +## Tech Stack +- Python 3.x +- Django 5.2.5 +- SQLite (development), PostgreSQL (production) +- Django MPTT for tree structures +- Django Nested Admin for inline editing +- Kubernetes for deployment +- ArgoCD for continuous deployment +- Traefik for ingress +- Gunicorn for WSGI server + +## Project Conventions + +### Code Style +- Language: German for user-facing strings and model names, English for code comments and internal naming +- Imports: Standard library first, then Django, then third-party, then local apps +- Model naming: German nouns (Dokument, Vorgabe, Person) +- Field naming: German for field names, English Django conventions +- Class naming: PascalCase for models, snake_case for functions/variables +- All models have __str__ methods returning meaningful German strings +- Use verbose_name and verbose_name_plural in Meta classes (German) + +### Architecture Patterns +- Django apps: abschnitte, dokumente, referenzen, rollen, stichworte, pages +- MPTT for hierarchical text sections +- Foreign keys with on_delete=models.PROTECT for important relationships +- Many-to-many with descriptive related_name +- Proxy models for different views (e.g., VorgabenTable) +- Management commands for data operations + +### Testing Strategy +- Django test framework +- Test class names in English, methods in English +- Comprehensive model tests +- Test both success and error cases +- Run with `python manage.py test` + +### Git Workflow +- Standard Git workflow +- Commits in English +- Use Gitea workflows for CI/CD + +## Domain Context +The system manages regulatory documents with numbered provisions that have validity dates. Provisions can conflict if they have overlapping date ranges for the same document, theme, and number. The system includes sanity checks for conflicts, diagram caching for visualization, and JSON export functionality. + +## Important Constraints +- German language for all user interfaces and data +- Strict validation of date ranges to prevent overlapping provisions +- Documents have types, authors, reviewers, and validity periods +- Provisions linked to themes, references, keywords, and relevant roles +- Active/inactive status for documents + +## External Dependencies +- Django ecosystem: MPTT, nested-admin, revproxy +- Kubernetes cluster for deployment +- ArgoCD for GitOps +- Traefik for load balancing +- External diagram services (diagramm_proxy) diff --git a/pages/templates/base.html b/pages/templates/base.html index c1a3e91..fed2831 100644 --- a/pages/templates/base.html +++ b/pages/templates/base.html @@ -41,6 +41,30 @@ alt="Zur Startseite" />

Vorgaben Informatiksicherheit BIT

+ + + {% if user.is_authenticated %} + + {% else %} + + {% endif %} diff --git a/pages/templates/registration/login.html b/pages/templates/registration/login.html new file mode 100644 index 0000000..c4cfe54 --- /dev/null +++ b/pages/templates/registration/login.html @@ -0,0 +1,43 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}Anmelden{% endblock %} + +{% block content %} +
+
+
+
+

Anmelden

+
+
+
+ {% csrf_token %} + + {% if form.errors %} +
+

Ihr Benutzername und Passwort stimmen nicht überein. Bitte versuchen Sie es erneut.

+
+ {% endif %} + +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/pages/templates/registration/password_change.html b/pages/templates/registration/password_change.html new file mode 100644 index 0000000..1a9645e --- /dev/null +++ b/pages/templates/registration/password_change.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}Passwort ändern{% endblock %} + +{% block content %} +
+
+
+
+

Passwort ändern

+
+
+
+ {% csrf_token %} + + {% if form.errors %} +
+

Bitte korrigieren Sie die Fehler unten.

+
+ {% endif %} + +
+ + + {% if form.old_password.errors %} +
{{ form.old_password.errors }}
+ {% endif %} +
+ +
+ + + {% if form.new_password1.errors %} +
{{ form.new_password1.errors }}
+ {% endif %} +
+ +
+ + + {% if form.new_password2.errors %} +
{{ form.new_password2.errors }}
+ {% endif %} +
+ +
+ + Abbrechen +
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/pages/templates/registration/password_change_done.html b/pages/templates/registration/password_change_done.html new file mode 100644 index 0000000..15cacda --- /dev/null +++ b/pages/templates/registration/password_change_done.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}Passwort geändert{% endblock %} + +{% block content %} +
+
+
+
+

Passwort erfolgreich geändert

+
+
+
+

Ihr Passwort wurde erfolgreich geändert.

+
+

+ Zurück zur Startseite +

+
+
+
+
+{% endblock %} \ No newline at end of file