diff --git a/quackscape/settings.py b/quackscape/settings.py
index 76e600b..2519556 100644
--- a/quackscape/settings.py
+++ b/quackscape/settings.py
@@ -3,6 +3,8 @@ from autosecretkey import AutoSecretKey
from pathlib import Path
from urllib.parse import urlparse
+from django.urls import reverse_lazy
+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -241,3 +243,9 @@ FFMPEG_OPTIONS = {
FFMPEG_DEFAULT_OPTION = ASK.config.get("ffmpeg", "DefaultOption", fallback="default")
# TODO: CSP settings
+
+# Authentication
+
+LOGIN_URL = reverse_lazy("quackscape.users:login")
+LOGIN_REDIRECT_URL = reverse_lazy("quackscape.users:categories")
+LOGOUT_REDIRECT_URL = reverse_lazy("quackscape.users:login")
\ No newline at end of file
diff --git a/quackscape/users/templates/users/base.html b/quackscape/users/templates/users/base.html
index 68d2f79..efa6be2 100644
--- a/quackscape/users/templates/users/base.html
+++ b/quackscape/users/templates/users/base.html
@@ -10,7 +10,11 @@
diff --git a/quackscape/users/templates/users/login.html b/quackscape/users/templates/users/login.html
new file mode 100644
index 0000000..42cf1d7
--- /dev/null
+++ b/quackscape/users/templates/users/login.html
@@ -0,0 +1,38 @@
+{% extends "users/base.html" %}
+
+{% block content %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/quackscape/users/urls.py b/quackscape/users/urls.py
index ef3c78e..a0a0690 100644
--- a/quackscape/users/urls.py
+++ b/quackscape/users/urls.py
@@ -1,13 +1,14 @@
-from .views import UserAreaMainView, CategoriesView, CategoryView, FileUploadView
+from .views import UserAreaMainView, CategoriesView, CategoryView, FileUploadView, Login, Logout
from django.urls import path
-from django.contrib.auth.views import LogoutView, LoginView
+
+app_name = 'quackscape.users'
urlpatterns = [
path('', UserAreaMainView.as_view(), name='user-area-main'),
path('categories/', CategoriesView.as_view(), name='categories'),
path('category/
/', CategoryView.as_view(), name='category'),
path('category//upload/', FileUploadView.as_view(), name='media-upload'),
- path('login/', LoginView.as_view(), name='login'),
- path('logout/', LogoutView.as_view(), name='logout'),
+ path('login/', Login.as_view(), name='login'),
+ path('logout/', Logout.as_view(), name='logout'),
]
\ No newline at end of file
diff --git a/quackscape/users/views.py b/quackscape/users/views.py
index 5c15108..8923023 100644
--- a/quackscape/users/views.py
+++ b/quackscape/users/views.py
@@ -1,5 +1,7 @@
from django.views.generic import TemplateView, ListView, DetailView
from django.http import Http404
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.contrib.auth.views import LoginView, LogoutView
from rest_framework.parsers import MultiPartParser, FormParser
from rest_framework.response import Response
@@ -21,12 +23,12 @@ class TitleMixin:
return context
-class UserAreaMainView(TitleMixin, TemplateView):
+class UserAreaMainView(LoginRequiredMixin, TitleMixin, TemplateView):
template_name = "users/base.html"
title = "User Area"
-class CategoriesView(TitleMixin, ListView):
+class CategoriesView(LoginRequiredMixin, TitleMixin, ListView):
model = Category
template_name = "users/categories.html"
title = "Categories"
@@ -42,7 +44,7 @@ class CategoriesView(TitleMixin, ListView):
return categories
-class CategoryView(TitleMixin, DetailView):
+class CategoryView(LoginRequiredMixin, TitleMixin, DetailView):
template_name = "users/category.html"
title = "Category"
context_object_name = "category"
@@ -56,17 +58,17 @@ class CategoryView(TitleMixin, DetailView):
raise Http404()
-class MediaUploadView(TitleMixin, TemplateView):
+class MediaUploadView(LoginRequiredMixin, TitleMixin, TemplateView):
template_name = "users/media_upload.html"
title = "Upload Media"
-class CategoryCreateView(TitleMixin, TemplateView):
+class CategoryCreateView(LoginRequiredMixin, TitleMixin, TemplateView):
template_name = "users/category_create.html"
title = "Create Category"
-class FileUploadView(GenericAPIView):
+class FileUploadView(LoginRequiredMixin, GenericAPIView):
parser_classes = (MultiPartParser, FormParser)
def get(self, request, *args, **kwargs):
@@ -93,3 +95,10 @@ class FileUploadView(GenericAPIView):
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+
+class Login(TitleMixin, LoginView):
+ title = "Login"
+ template_name = "users/login.html"
+
+class Logout(LogoutView):
+ pass
\ No newline at end of file