From 3cd95443e6f14bed16eadcf598708e71a0cbed0f Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 14 Dec 2020 13:26:47 -0500 Subject: [PATCH] Add basic login/logout pages and nav items --- recmaint/settings.py | 2 ++ recmaint/urls.py | 9 +++++++++ templates/auth/login.djhtml | 35 +++++++++++++++++++++++++++++++++++ templates/auth/logout.djhtml | 10 ++++++++++ templates/base.djhtml | 15 +++++++++++++-- 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 templates/auth/login.djhtml create mode 100644 templates/auth/logout.djhtml diff --git a/recmaint/settings.py b/recmaint/settings.py index b006d46..6b43ba9 100644 --- a/recmaint/settings.py +++ b/recmaint/settings.py @@ -101,6 +101,8 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] +# Default URL to redirect to after authentication +LOGIN_REDIRECT_URL = '/' # Internationalization # https://docs.djangoproject.com/en/3.1/topics/i18n/ diff --git a/recmaint/urls.py b/recmaint/urls.py index d849ca1..99d44dc 100644 --- a/recmaint/urls.py +++ b/recmaint/urls.py @@ -16,9 +16,18 @@ Including another URLconf from django.contrib import admin from django.shortcuts import redirect from django.urls import include, path +from django.contrib.auth.views import LoginView, LogoutView + + urlpatterns = [ path('', lambda request: redirect('/tasks/')), path('tasks/', include('tasks.urls')), path('admin/', admin.site.urls), + path('auth/', include([ + path('login/', LoginView.as_view( + template_name="auth/login.djhtml", + redirect_authenticated_user=True), name='login'), + path('logout/', LogoutView.as_view(template_name="auth/logout.djhtml"), name='logout'), + ])) ] diff --git a/templates/auth/login.djhtml b/templates/auth/login.djhtml new file mode 100644 index 0000000..cf56fe6 --- /dev/null +++ b/templates/auth/login.djhtml @@ -0,0 +1,35 @@ +{% extends "base.djhtml" %} + +{% block title %} Login {% endblock %} + +{% block content %} + {% if form.errors %} +

Your username and password didn't match. Please try again.

+ {% endif %} + + {% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} + {% endif %} + +
+ {% csrf_token %} + + + + + + + + + +
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
+ + +
+ +{% endblock %} diff --git a/templates/auth/logout.djhtml b/templates/auth/logout.djhtml new file mode 100644 index 0000000..0d8e7f4 --- /dev/null +++ b/templates/auth/logout.djhtml @@ -0,0 +1,10 @@ +{% extends "base.djhtml" %} + +{% block title %} Logout {% endblock %} + +{% block content %} +
+

Logged out!

+ Click here to login again. +
+{% endblock %} diff --git a/templates/base.djhtml b/templates/base.djhtml index 7487695..1a69787 100644 --- a/templates/base.djhtml +++ b/templates/base.djhtml @@ -12,9 +12,20 @@