mirror of
https://github.com/kristoferssolo/FOSSDB.git
synced 2025-10-21 17:50:35 +00:00
Created custom login form
This commit is contained in:
parent
abf636775c
commit
5189b4a537
@ -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": "",
|
||||
}
|
||||
|
||||
@ -8,18 +8,7 @@
|
||||
<form method="post"
|
||||
class="flex flex-col items-center justify-center space-y-4 my-auto">
|
||||
{% csrf_token %}
|
||||
<input type="text"
|
||||
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 %}
|
||||
{{ form }}
|
||||
<button type="submit"
|
||||
id="submit-button"
|
||||
class="button submit-button-disabled text-lightsteelblue-100 bg-slategray-200">Login</button>
|
||||
|
||||
@ -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()
|
||||
|
||||
0
src/apps/fossdb/templates/admin/add.html
Normal file
0
src/apps/fossdb/templates/admin/add.html
Normal file
@ -9,7 +9,7 @@
|
||||
{% csrf_token %}
|
||||
<input type="text"
|
||||
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"
|
||||
class="button submit-button-disabled text-lightsteelblue-100 bg-slategray-200 uppercase font-bold"
|
||||
type="submit">Delete</button>
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
<h1 class="font-abel text-4xl mb-8">Search Results</h1>
|
||||
<div class="grid grid-cols-1 gap-4">
|
||||
{% 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 }}"
|
||||
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>
|
||||
</a>
|
||||
<p class="max-w-xs text-justify">{{ project.description|slice:500 }}</p>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user