From 5189b4a537d804a0ac558217aed9c7a429c9956c Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 29 Jun 2023 17:10:03 +0000 Subject: [PATCH] Created custom login form --- src/apps/account/forms.py | 56 +++++++++++++++++++++- src/apps/account/templates/login.html | 13 +---- src/apps/account/views.py | 5 +- src/apps/fossdb/templates/admin/add.html | 0 src/apps/fossdb/templates/delete_view.html | 2 +- src/apps/fossdb/templates/search.html | 4 +- 6 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 src/apps/fossdb/templates/admin/add.html diff --git a/src/apps/account/forms.py b/src/apps/account/forms.py index c5ac173..520379c 100644 --- a/src/apps/account/forms.py +++ b/src/apps/account/forms.py @@ -1,12 +1,31 @@ from django import forms -from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.forms import AuthenticationForm, UserCreationForm from .models import User +class LoginForm(AuthenticationForm): + def __init__(self, *args, **kwargs): + super(LoginForm, self).__init__(*args, **kwargs) + self.fields["username"].widget = forms.TextInput( + attrs={ + "placeholder": "Username", + "class": "verify form-field submit-form", + } + ) + self.fields["username"].label = "" + self.fields["password"].widget = forms.PasswordInput( + attrs={ + "placeholder": "Password", + "class": "verify form-field submit-form", + } + ) + self.fields["password"].label = "" + + class SignUpForm(UserCreationForm): - email = forms.EmailField(required=False, help_text="Optional.") + email = forms.EmailField(required=False) class Meta: model = User @@ -16,3 +35,36 @@ class SignUpForm(UserCreationForm): "password1", "password2", ) + + widgets = { + "username": forms.TextInput( + attrs={ + "placeholder": "Username", + "class": "verify form-field submit-form", + } + ), + "email": forms.EmailInput( + attrs={ + "placeholder": "Email (optional)", + "class": "verify form-field submit-form", + } + ), + "password1": forms.PasswordInput( + attrs={ + "placeholder": "Password", + "class": "verify form-field submit-form", + } + ), + "password2": forms.PasswordInput( + attrs={ + "placeholder": "Confirm password", + "class": "verify form-field submit-form", + } + ), + } + labels = { + "username": "", + "email": "", + "password1": "", + "password2": "", + } diff --git a/src/apps/account/templates/login.html b/src/apps/account/templates/login.html index c67c986..44b76df 100644 --- a/src/apps/account/templates/login.html +++ b/src/apps/account/templates/login.html @@ -8,18 +8,7 @@
{% csrf_token %} - - {% if form.username.errors %}

{{ form.username.errors }}

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

{{ form.password.errors }}

{% endif %} + {{ form }} diff --git a/src/apps/account/views.py b/src/apps/account/views.py index da3c102..585876f 100644 --- a/src/apps/account/views.py +++ b/src/apps/account/views.py @@ -1,8 +1,7 @@ from django.contrib.auth import authenticate, login -from django.contrib.auth.forms import AuthenticationForm from django.shortcuts import get_object_or_404, redirect, render -from .forms import SignUpForm +from .forms import LoginForm, SignUpForm from .models import User @@ -34,7 +33,7 @@ def signup_view(request): def login_view(request): - form = AuthenticationForm(data=request.POST or None) + form = LoginForm(data=request.POST or None) if request.method == "POST": if form.is_valid(): user = form.get_user() diff --git a/src/apps/fossdb/templates/admin/add.html b/src/apps/fossdb/templates/admin/add.html new file mode 100644 index 0000000..e69de29 diff --git a/src/apps/fossdb/templates/delete_view.html b/src/apps/fossdb/templates/delete_view.html index c260639..aaa3751 100644 --- a/src/apps/fossdb/templates/delete_view.html +++ b/src/apps/fossdb/templates/delete_view.html @@ -9,7 +9,7 @@ {% csrf_token %} + class="text-center form-field border-slategray-200 hover:border-indianred-100 bg-gray-300 focus:border-indianred-100 transition delay-200 ease-linear" /> diff --git a/src/apps/fossdb/templates/search.html b/src/apps/fossdb/templates/search.html index 67a4e10..3a18b3b 100644 --- a/src/apps/fossdb/templates/search.html +++ b/src/apps/fossdb/templates/search.html @@ -7,9 +7,9 @@

Search Results

{% for project in projects %} -