ungleich-user/dal/forms.py

32 lines
1,008 B
Python
Raw Normal View History

2019-02-19 22:16:05 +00:00
from django import forms
from django.contrib.auth import authenticate
from django.utils.translation import ugettext_lazy as _
class LoginForm(forms.Form):
email = forms.CharField(widget=forms.TextInput())
password = forms.CharField(widget=forms.PasswordInput())
class Meta:
fields = ['email', 'password']
def clean(self):
email = self.cleaned_data.get('email')
password = self.cleaned_data.get('password')
if self.errors:
return self.cleaned_data
is_auth = authenticate(username=email, password=password)
if not is_auth:
raise forms.ValidationError(
2019-02-19 22:39:47 +00:00
_("Your username and/or password were incorrect.")
)
2019-02-23 08:19:20 +00:00
# elif is_auth.validated == 0:
# raise forms.ValidationError(
# _("Your account is not activated yet.")
# )
2019-02-19 22:16:05 +00:00
return self.cleaned_data
def clean_email(self):
email = self.cleaned_data.get('email')
return email