Commit c4079a1c authored by William Colmenares's avatar William Colmenares

request the username in login instead of the email

parent de44229a
......@@ -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 } )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment