request the username in login instead of the email
This commit is contained in:
parent
de44229ac2
commit
c4079a1c1d
2 changed files with 9 additions and 9 deletions
14
dal/forms.py
14
dal/forms.py
|
@ -4,18 +4,18 @@ from django.utils.translation import ugettext_lazy as _
|
|||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
email = forms.CharField(widget=forms.TextInput())
|
||||
username = forms.CharField(widget=forms.TextInput())
|
||||
password = forms.CharField(widget=forms.PasswordInput())
|
||||
|
||||
class Meta:
|
||||
fields = ['email', 'password']
|
||||
fields = ['username', 'password']
|
||||
|
||||
def clean(self):
|
||||
email = self.cleaned_data.get('email')
|
||||
username = self.cleaned_data.get('username')
|
||||
password = self.cleaned_data.get('password')
|
||||
if self.errors:
|
||||
return self.cleaned_data
|
||||
is_auth = authenticate(username=email, password=password)
|
||||
is_auth = authenticate(username=username, password=password)
|
||||
if not is_auth:
|
||||
raise forms.ValidationError(
|
||||
_("Your username and/or password were incorrect.")
|
||||
|
@ -26,6 +26,6 @@ class LoginForm(forms.Form):
|
|||
# )
|
||||
return self.cleaned_data
|
||||
|
||||
def clean_email(self):
|
||||
email = self.cleaned_data.get('email')
|
||||
return email
|
||||
def clean_username(self):
|
||||
username = self.cleaned_data.get('username')
|
||||
return username
|
||||
|
|
|
@ -37,9 +37,9 @@ class Index(FormView):
|
|||
success_url = 'useroptions.html'
|
||||
|
||||
def form_valid(self, form):
|
||||
email = form.cleaned_data.get('email')
|
||||
username = form.cleaned_data.get('username')
|
||||
password = form.cleaned_data.get('password')
|
||||
user = authenticate(username=email, password=password)
|
||||
user = authenticate(username=username, password=password)
|
||||
if user is not None:
|
||||
login(self.request, user)
|
||||
return render(self.request, 'useroptions.html', { 'user': user } )
|
||||
|
|
Loading…
Reference in a new issue