Added basic authentication support using django.contrib.auth and requiring login using the django.contrib.auth.decorators.login_required decorator.

This commit is contained in:
Johannes Randerath 2024-06-14 15:00:11 +02:00
parent fe1273813c
commit ff40cf8edb
4 changed files with 17 additions and 2 deletions

View File

@ -0,0 +1,6 @@
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>

View File

@ -0,0 +1,6 @@
<h2>Register</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Register</button>
</form>

View File

@ -14,6 +14,7 @@ from .models import *
from .forms import * from .forms import *
import json import json
from datetime import datetime from datetime import datetime
from django.contrib.auth.decorators import login_required
def get_timetable(r, trips, stop_sequences): def get_timetable(r, trips, stop_sequences):
""" """
@ -48,7 +49,7 @@ def get_timetable(r, trips, stop_sequences):
timetable["stop_times"] = sts timetable["stop_times"] = sts
return timetable return timetable
@login_required
def index(request): def index(request):
stops = {s.stop_id: {name: getattr(s, name) for name in ['stop_name', 'stop_lat', 'stop_lon']} for s in Stop.objects.all()} stops = {s.stop_id: {name: getattr(s, name) for name in ['stop_name', 'stop_lat', 'stop_lon']} for s in Stop.objects.all()}
route_name = lambda r : r.route_short_name if r.route_short_name else r.route_long_name route_name = lambda r : r.route_short_name if r.route_short_name else r.route_long_name

View File

@ -1,10 +1,12 @@
""" """
URL configuration for transport_accessibility project. URL configuration for transport_accessibility project.
""" """
from django.contrib import auth as auth
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include("pt_map.urls")) path('', include("pt_map.urls")),
path("accounts/", include("django.contrib.auth.urls")),
] ]