You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TeamFlash/sahara/main/forms.py

53 lines
1.9 KiB

from django import forms
6 months ago
from django.contrib.auth.forms import AuthenticationForm
from .models import User
6 months ago
class UserRegistrationForm(forms.ModelForm):
password = forms.CharField(
widget=forms.PasswordInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your password',
})
)
6 months ago
confirm_password = forms.CharField(
widget=forms.PasswordInput(attrs={
'class': 'form-control',
'placeholder': 'Confirm your password',
})
)
6 months ago
class Meta:
model = User
fields = ['first_name', 'last_name', 'email', 'password']
widgets = {
'first_name': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your first name',
}),
'last_name': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your last name',
}),
'email': forms.EmailInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your email address',
}),
}
def clean(self):
cleaned_data = super().clean()
password = cleaned_data.get('password')
confirm_password = cleaned_data.get('confirm_password')
6 months ago
if password and confirm_password and password != confirm_password:
raise forms.ValidationError("Passwords do not match.")
6 months ago
class UserLoginForm(AuthenticationForm):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(UserLoginForm, self).__init__(*args, **kwargs)
# Change the username field label and placeholder to 'Email'
self.fields['username'].label = 'Email'
self.fields['username'].widget.attrs.update({'placeholder': 'Enter your email'})
self.fields['password'].widget.attrs.update({'placeholder': 'Enter your password'})