From aeb9e58ccf79fdfb20052edf98988d149f2694fa Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Sat, 7 Dec 2024 15:18:02 +0000 Subject: [PATCH] implement login form --- penparse/webui/forms.py | 15 +++- penparse/webui/templates/register.html | 4 +- .../webui/templates/registration/login.html | 74 +++++++++++++++++++ penparse/webui/views.py | 31 -------- 4 files changed, 91 insertions(+), 33 deletions(-) create mode 100644 penparse/webui/templates/registration/login.html diff --git a/penparse/webui/forms.py b/penparse/webui/forms.py index 1eed6e0..d626266 100644 --- a/penparse/webui/forms.py +++ b/penparse/webui/forms.py @@ -1,6 +1,19 @@ from django import forms from .models import User -from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.forms import UserCreationForm, AuthenticationForm + + +class LoginForm(AuthenticationForm): + class Meta: + model = User + fields = ['email', 'password'] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['email'].widget.attrs.update( + {'class': 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline'}) + self.fields['password'].widget.attrs.update( + {'class': 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline'}) class RegisterForm(UserCreationForm): diff --git a/penparse/webui/templates/register.html b/penparse/webui/templates/register.html index 2eb2f8b..aa6f55b 100644 --- a/penparse/webui/templates/register.html +++ b/penparse/webui/templates/register.html @@ -80,7 +80,9 @@

Already have an account? - Sign in + Sign in

diff --git a/penparse/webui/templates/registration/login.html b/penparse/webui/templates/registration/login.html new file mode 100644 index 0000000..13ae6ae --- /dev/null +++ b/penparse/webui/templates/registration/login.html @@ -0,0 +1,74 @@ +{% extends "main.html" %} {% block content %} +
+
+
+

+ Log in to AnnoMemo +

+ {% if form.non_field_errors %} +
+ {% for error in form.non_field_errors %} {{ error }} {% endfor %} +
+ {% endif %} +
+ {% csrf_token %} +
+ + + {% if form.username.errors %} +

+ {{ form.username.errors.0 }} +

+ {% endif %} +
+
+ + + + {% if form.password.errors %} +

+ {{ form.password.errors.0 }} +

+ {% endif %} +
+
+ +
+
+
+
+

+ Don't have an account? + Sign up +

+
+
+
+{% endblock %} diff --git a/penparse/webui/views.py b/penparse/webui/views.py index 7aa4659..5cf51ea 100644 --- a/penparse/webui/views.py +++ b/penparse/webui/views.py @@ -33,34 +33,3 @@ def register(request: HttpRequest): form = RegisterForm() return render(request, 'register.html', {'form': form}) - - # email = request.POST.get('email') - # password = request.POST.get('password') - # confirm_password = request.POST.get('confirm_password') - - # errors = False - - # if not email: - # messages.error(request, 'Email is required') - # errors = True - - # if not password or len(password) < 8: - # messages.error(request, 'Password must be at least 8 characters long') - # errors = True - - # if password != confirm_password: - # messages.error(request, 'Passwords do not match') - # errors = True - - # if not errors: - - # if User.objects.filter(email=email).exists(): - # messages.error(request, 'Email already exists') - # else: - # user = User.objects.create_user( - # username=username, email=email, password=password) # type: ignore - # user.save() - # messages.success(request, 'Account created successfully') - # return redirect('login') - - return render(request, 'register.html')