From 2846768e61bec535f33def5ae72ea9c151d0fed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Thu, 14 May 2020 14:49:07 +0200 Subject: [PATCH] Introduce self-registration and add simple user startpage Add django-registration-redux dependency Adapt settings and urls Add view logged-in users to either proceed to the backend or logout --- AKModel/templates/AKModel/user.html | 42 +++++++++++++++++++++++++++++ AKModel/urls.py | 1 + AKModel/views.py | 5 ++++ AKPlanning/settings.py | 5 ++++ AKPlanning/urls.py | 4 ++- requirements.txt | 3 ++- 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 AKModel/templates/AKModel/user.html diff --git a/AKModel/templates/AKModel/user.html b/AKModel/templates/AKModel/user.html new file mode 100644 index 00000000..7c74fde8 --- /dev/null +++ b/AKModel/templates/AKModel/user.html @@ -0,0 +1,42 @@ +{% extends 'base.html' %} + +{% load fontawesome_5 %} +{% load i18n %} +{% load static %} + +{% load tags_AKModel %} + +{% block imports %} + + {{ block.super }} + + <link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}"> + +{% endblock %} + +{% block breadcrumbs %} + <li class="breadcrumb-item"> + {% if 'AKDashboard'|check_app_installed %} + <a href="{% url 'dashboard:dashboard' %}">AKPlanning</a> + {% else %} + AKPlanning + {% endif %} + </li> + <li class="breadcrumb-item">User: {{ user.get_username }}</li> +{% endblock %} + +{% block content %} + {% include "messages.html" %} + + <h1>{% trans "Hello" %} {{ user }}!</h1> + + {% if user.is_staff %} + <a class="btn btn-primary" href="{% url "admin:index" %}">{% trans "Go to backend" %}</a> + {% else %} + <div class="alert alert-warning" style="margin-top:20px;margin-bottom: 20px;"> + {% trans "Please wait for an administrator to confirm your account" %} + </div> + {% endif %} + <a class="btn btn-danger" href="{% url "logout" %}">{% trans "Logout" %}</a> + +{% endblock %} diff --git a/AKModel/urls.py b/AKModel/urls.py index 4ed6404c..a469c54f 100644 --- a/AKModel/urls.py +++ b/AKModel/urls.py @@ -20,4 +20,5 @@ urlpatterns = [ path('api/', include(api_router.urls), name='api'), ]) ), + path('user/', views.UserView.as_view(), name="user"), ] diff --git a/AKModel/views.py b/AKModel/views.py index 88656ef7..1d6b95eb 100644 --- a/AKModel/views.py +++ b/AKModel/views.py @@ -1,4 +1,5 @@ from django.shortcuts import get_object_or_404 +from django.views.generic import TemplateView from rest_framework import viewsets, permissions, mixins from AKModel.models import Event, AK, AKSlot, Room, AKTrack, AKCategory, AKOwner @@ -95,3 +96,7 @@ class AKSlotViewSet(EventSlugMixin, mixins.RetrieveModelMixin, mixins.ListModelM def get_queryset(self): return AKSlot.objects.filter(event=self.event) + + +class UserView(TemplateView): + template_name = "AKModel/user.html" diff --git a/AKPlanning/settings.py b/AKPlanning/settings.py index d9bcb96d..83d1340a 100644 --- a/AKPlanning/settings.py +++ b/AKPlanning/settings.py @@ -48,6 +48,7 @@ INSTALLED_APPS = [ 'timezone_field', 'rest_framework', 'simple_history', + 'registration', ] MIDDLEWARE = [ @@ -169,4 +170,8 @@ PLAN_SHOW_HIERARCHY = True # For which time (in seconds) should changes of akslots be highlighted in plan? PLAN_MAX_HIGHLIGHT_UPDATE_SECONDS = 2 * 60 * 60 +# Registration/login behavior +SIMPLE_BACKEND_REDIRECT_URL = "/user/" +LOGIN_REDIRECT_URL = SIMPLE_BACKEND_REDIRECT_URL + include(optional("settings/*.py")) diff --git a/AKPlanning/urls.py b/AKPlanning/urls.py index aa5f4538..e7c592d8 100644 --- a/AKPlanning/urls.py +++ b/AKPlanning/urls.py @@ -19,8 +19,10 @@ from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('accounts/', include('django.contrib.auth.urls')), + path('accounts/', include('registration.backends.simple.urls')), path('', include('AKModel.urls', namespace='model')), - path('i18n/', include('django.conf.urls.i18n')) + path('i18n/', include('django.conf.urls.i18n')), ] # Load URLs dynamically (only if components are active) diff --git a/requirements.txt b/requirements.txt index cb5e8031..64638270 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ django-fontawesome-5==1.0.18 django-split-settings==1.0.1 django-timezone-field==4.0 djangorestframework==3.11.0 -django-simple-history==2.10.0 \ No newline at end of file +django-simple-history==2.10.0 +django-registration-redux==2.8 -- GitLab