first comit
This commit is contained in:
94
accounts/forms.py
Normal file
94
accounts/forms.py
Normal file
@@ -0,0 +1,94 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordChangeForm, UsernameField, PasswordResetForm, SetPasswordForm, UserChangeForm
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.conf import settings
|
||||
|
||||
class RegistrationForm(UserCreationForm):
|
||||
def validate_email_domain(email):
|
||||
for domain in settings.ALLOWED_EMAIL_DOMAINS:
|
||||
#if "@rawcut.tv" in email or "@tomos.tv" in email or "@themainframe.co.uk" in email:
|
||||
if domain in email:
|
||||
break
|
||||
else:
|
||||
raise ValidationError(
|
||||
_('%(email)s - %(domain)s not allowed'),
|
||||
params={'email': email, 'domain':domain},
|
||||
)
|
||||
|
||||
password1 = forms.CharField(
|
||||
label=_("Password"),
|
||||
widget=forms.PasswordInput(attrs={'class': 'form-control form-control-user', 'placeholder': 'Password'}),
|
||||
)
|
||||
password2 = forms.CharField(
|
||||
label=_("Confirm Password"),
|
||||
widget=forms.PasswordInput(attrs={
|
||||
'class': 'form-control form-control-user', 'placeholder': 'Confirm Password'
|
||||
}),
|
||||
)
|
||||
username= forms.CharField(
|
||||
widget=forms.TextInput(attrs={
|
||||
'class': 'form-control form-control-user',
|
||||
'placeholder': 'Username'
|
||||
}),
|
||||
)
|
||||
email= forms.EmailField(required=True, validators=[validate_email_domain],
|
||||
widget=forms.EmailInput(attrs={
|
||||
'class': 'form-control form-control-user',
|
||||
'placeholder': 'Email',
|
||||
'name': 'email'
|
||||
})
|
||||
)
|
||||
def save(self, commit=True):
|
||||
user = super(RegistrationForm, self).save(commit=False)
|
||||
user.email = self.cleaned_data['email']
|
||||
if commit:
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def delete(self):
|
||||
user = super(RegistrationForm, self).save(commit=False)
|
||||
user.delete()
|
||||
return 'User deleted'
|
||||
|
||||
class LoginForm(AuthenticationForm):
|
||||
username = forms.EmailField(widget=forms.EmailInput(attrs={
|
||||
'class': 'form-control form-control-user',
|
||||
'placeholder': 'Email',
|
||||
"autocomplete": "email"
|
||||
}))
|
||||
password = forms.CharField(
|
||||
label=_("Your Password"),
|
||||
strip=False,
|
||||
widget=forms.PasswordInput(attrs={
|
||||
"class": "form-control form-control-user",
|
||||
"placeholder": "Password",
|
||||
"autocomplete":"current-password"
|
||||
}))
|
||||
class UserPasswordResetForm(PasswordResetForm):
|
||||
email = forms.EmailField(widget=forms.EmailInput(attrs={
|
||||
'class': 'form-control form-control-user',
|
||||
'placeholder': 'Email'
|
||||
}))
|
||||
|
||||
class UserSetPasswordForm(SetPasswordForm):
|
||||
new_password1 = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={
|
||||
'class': 'form-control form-control-user', 'placeholder': 'New Password'
|
||||
}), label="New Password")
|
||||
new_password2 = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={
|
||||
'class': 'form-control form-control-user', 'placeholder': 'Confirm New Password'
|
||||
}), label="Confirm New Password")
|
||||
|
||||
class UserPasswordChangeForm(PasswordChangeForm):
|
||||
old_password = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={
|
||||
'class': 'form-control form-control-user', 'placeholder': 'Old Password'
|
||||
}), label='Old Password')
|
||||
new_password1 = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={
|
||||
'class': 'form-control form-control-user', 'placeholder': 'New Password'
|
||||
}), label="New Password")
|
||||
new_password2 = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={
|
||||
'class': 'form-control form-control-user', 'placeholder': 'Confirm New Password'
|
||||
}), label="Confirm New Password")
|
||||
|
||||
Reference in New Issue
Block a user