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):
|
2019-05-02 08:10:06 +00:00
|
|
|
username = forms.CharField(widget=forms.TextInput())
|
2019-02-19 22:16:05 +00:00
|
|
|
password = forms.CharField(widget=forms.PasswordInput())
|
|
|
|
|
|
|
|
class Meta:
|
2019-05-02 08:10:06 +00:00
|
|
|
fields = ['username', 'password']
|
2019-02-19 22:16:05 +00:00
|
|
|
|
|
|
|
def clean(self):
|
2019-05-02 08:10:06 +00:00
|
|
|
username = self.cleaned_data.get('username')
|
2019-02-19 22:16:05 +00:00
|
|
|
password = self.cleaned_data.get('password')
|
|
|
|
if self.errors:
|
|
|
|
return self.cleaned_data
|
2019-05-02 08:10:06 +00:00
|
|
|
is_auth = authenticate(username=username, password=password)
|
2019-02-19 22:16:05 +00:00
|
|
|
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
|
|
|
|
|
2019-05-02 08:10:06 +00:00
|
|
|
def clean_username(self):
|
|
|
|
username = self.cleaned_data.get('username')
|
|
|
|
return username
|