request the username in login instead of the email

This commit is contained in:
wcolmenares 2019-05-02 04:10:06 -04:00
parent de44229ac2
commit c4079a1c1d
2 changed files with 9 additions and 9 deletions

View file

@ -4,18 +4,18 @@ from django.utils.translation import ugettext_lazy as _
class LoginForm(forms.Form): class LoginForm(forms.Form):
email = forms.CharField(widget=forms.TextInput()) username = forms.CharField(widget=forms.TextInput())
password = forms.CharField(widget=forms.PasswordInput()) password = forms.CharField(widget=forms.PasswordInput())
class Meta: class Meta:
fields = ['email', 'password'] fields = ['username', 'password']
def clean(self): def clean(self):
email = self.cleaned_data.get('email') username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password') password = self.cleaned_data.get('password')
if self.errors: if self.errors:
return self.cleaned_data return self.cleaned_data
is_auth = authenticate(username=email, password=password) is_auth = authenticate(username=username, password=password)
if not is_auth: if not is_auth:
raise forms.ValidationError( raise forms.ValidationError(
_("Your username and/or password were incorrect.") _("Your username and/or password were incorrect.")
@ -26,6 +26,6 @@ class LoginForm(forms.Form):
# ) # )
return self.cleaned_data return self.cleaned_data
def clean_email(self): def clean_username(self):
email = self.cleaned_data.get('email') username = self.cleaned_data.get('username')
return email return username

View file

@ -37,9 +37,9 @@ class Index(FormView):
success_url = 'useroptions.html' success_url = 'useroptions.html'
def form_valid(self, form): def form_valid(self, form):
email = form.cleaned_data.get('email') username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password') password = form.cleaned_data.get('password')
user = authenticate(username=email, password=password) user = authenticate(username=username, password=password)
if user is not None: if user is not None:
login(self.request, user) login(self.request, user)
return render(self.request, 'useroptions.html', { 'user': user } ) return render(self.request, 'useroptions.html', { 'user': user } )