diff --git a/accounts/forms.py b/accounts/forms.py
index bd59f15..b093b3e 100644
--- a/accounts/forms.py
+++ b/accounts/forms.py
@@ -1,4 +1,5 @@
from django import forms
+from django.contrib.auth.forms import AuthenticationForm
class CreateAccountForm(forms.Form):
@@ -32,3 +33,26 @@ class CreateAccountForm(forms.Form):
def clean(self):
cleaned_data = super().clean()
return cleaned_data
+
+
+class EmailAuthenticationForm(AuthenticationForm):
+ username = forms.EmailField(
+ label="Email",
+ widget=forms.EmailInput(
+ attrs={
+ "id": "email",
+ "class": "form-control",
+ }
+ ),
+ )
+
+ password = forms.CharField(
+ label="Password",
+ strip=False,
+ widget=forms.PasswordInput(
+ attrs={
+ "id": "password",
+ "class": "form-control",
+ }
+ ),
+ )
diff --git a/accounts/templates/login.html b/accounts/templates/login.html
new file mode 100644
index 0000000..6492bf1
--- /dev/null
+++ b/accounts/templates/login.html
@@ -0,0 +1,56 @@
+{% extends 'base.html' %}
+{% load static %}
+
+{% block title %}Login - Fables{% endblock %}
+
+{% block content %}
+
Login
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/accounts/urls.py b/accounts/urls.py
index 4952d82..f362340 100644
--- a/accounts/urls.py
+++ b/accounts/urls.py
@@ -1,10 +1,10 @@
from django.urls import path
-from home import views as home_views
-
from . import views
+from .views import CustomLoginView, CustomLogoutView
urlpatterns = [
- path("", home_views.home, name="home"),
path("create/", views.create_account, name="create_account"),
+ path("login/", CustomLoginView.as_view(), name="login"),
+ path("logout/", CustomLogoutView.as_view(), name="logout"),
]
diff --git a/accounts/views.py b/accounts/views.py
index 399d268..c4c7f50 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -1,9 +1,10 @@
import logging
from django.contrib import messages
+from django.contrib.auth.views import LoginView, LogoutView
from django.shortcuts import redirect, render
-from .forms import CreateAccountForm
+from .forms import CreateAccountForm, EmailAuthenticationForm
from .models import Account
logger = logging.getLogger(__name__)
@@ -43,3 +44,13 @@ def create_account(request):
logger.debug("Rendering create account form (GET request)")
return render(request, "create_account.html", {"form": form})
+
+
+class CustomLoginView(LoginView):
+ template_name = "login.html"
+ authentication_form = EmailAuthenticationForm
+ redirect_authenticated_user = True
+
+
+class CustomLogoutView(LogoutView):
+ next_page = "/"
diff --git a/fables/settings.py b/fables/settings.py
index 99a45de..709382a 100644
--- a/fables/settings.py
+++ b/fables/settings.py
@@ -92,6 +92,9 @@
# User Model
AUTH_USER_MODEL = "accounts.Account"
+LOGIN_REDIRECT_URL = "/"
+LOGOUT_REDIRECT_URL = "/"
+LOGIN_URL = "/accounts/login"
# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
diff --git a/home/templates/base.html b/home/templates/base.html
index f196005..e039a33 100644
--- a/home/templates/base.html
+++ b/home/templates/base.html
@@ -15,6 +15,7 @@
diff --git a/home/views.py b/home/views.py
index 73e7ec4..4b6ef3c 100644
--- a/home/views.py
+++ b/home/views.py
@@ -1,5 +1,7 @@
+from django.contrib.auth.decorators import login_required
from django.shortcuts import render
+@login_required
def home(request):
return render(request, "home.html")