Created custom login form

This commit is contained in:
Kristofers Solo 2023-06-29 17:10:03 +00:00
parent abf636775c
commit 5189b4a537
6 changed files with 60 additions and 20 deletions

View File

@ -1,12 +1,31 @@
from django import forms from django import forms
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
from .models import User 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): class SignUpForm(UserCreationForm):
email = forms.EmailField(required=False, help_text="Optional.") email = forms.EmailField(required=False)
class Meta: class Meta:
model = User model = User
@ -16,3 +35,36 @@ class SignUpForm(UserCreationForm):
"password1", "password1",
"password2", "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": "",
}

View File

@ -8,18 +8,7 @@
<form method="post" <form method="post"
class="flex flex-col items-center justify-center space-y-4 my-auto"> class="flex flex-col items-center justify-center space-y-4 my-auto">
{% csrf_token %} {% csrf_token %}
<input type="text" {{ form }}
placeholder="Username"
name="username"
value="{{ form.username.value|default:'' }}"
class="verify form-field submit-form" />
{% if form.username.errors %}<p class="text-indianred-100 text-xs italic">{{ form.username.errors }}</p>{% endif %}
<input type="password"
placeholder="Password"
name="password"
value="{{ form.username.value|default:'' }}"
class="verify form-field submit-form" />
{% if form.password.errors %}<p class="text-indianred-100 text-xs italic">{{ form.password.errors }}</p>{% endif %}
<button type="submit" <button type="submit"
id="submit-button" id="submit-button"
class="button submit-button-disabled text-lightsteelblue-100 bg-slategray-200">Login</button> class="button submit-button-disabled text-lightsteelblue-100 bg-slategray-200">Login</button>

View File

@ -1,8 +1,7 @@
from django.contrib.auth import authenticate, login 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 django.shortcuts import get_object_or_404, redirect, render
from .forms import SignUpForm from .forms import LoginForm, SignUpForm
from .models import User from .models import User
@ -34,7 +33,7 @@ def signup_view(request):
def login_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 request.method == "POST":
if form.is_valid(): if form.is_valid():
user = form.get_user() user = form.get_user()

View File

View File

@ -9,7 +9,7 @@
{% csrf_token %} {% csrf_token %}
<input type="text" <input type="text"
id="confirm-input" id="confirm-input"
class="text-center form-field border-slategray-200 hover:border-indianred-100 bg-gray-300 focus:border-indianred-100" /> class="text-center form-field border-slategray-200 hover:border-indianred-100 bg-gray-300 focus:border-indianred-100 transition delay-200 ease-linear" />
<button id="submit-button" <button id="submit-button"
class="button submit-button-disabled text-lightsteelblue-100 bg-slategray-200 uppercase font-bold" class="button submit-button-disabled text-lightsteelblue-100 bg-slategray-200 uppercase font-bold"
type="submit">Delete</button> type="submit">Delete</button>

View File

@ -7,9 +7,9 @@
<h1 class="font-abel text-4xl mb-8">Search Results</h1> <h1 class="font-abel text-4xl mb-8">Search Results</h1>
<div class="grid grid-cols-1 gap-4"> <div class="grid grid-cols-1 gap-4">
{% for project in projects %} {% for project in projects %}
<div class="border border-skyblue-300 p-8 flex flex-row gap-4 justify-between"> <div class="border border-steelblue-100 p-8 flex flex-row gap-4 justify-between">
<a href="{{ project.get_absolute_url }}" <a href="{{ project.get_absolute_url }}"
class="hover:text-skyblue-300 transition duration-300 ease-linear"> class="hover:text-steelblue-100 transition duration-300 ease-linear">
<h2 class="font-abel text-2xl">{{ project.name }}</h2> <h2 class="font-abel text-2xl">{{ project.name }}</h2>
</a> </a>
<p class="max-w-xs text-justify">{{ project.description|slice:500 }}</p> <p class="max-w-xs text-justify">{{ project.description|slice:500 }}</p>