diff --git a/apps/auth/forms.py b/apps/auth/forms.py index 0baea362..6977a3c2 100644 --- a/apps/auth/forms.py +++ b/apps/auth/forms.py @@ -1,4 +1,5 @@ from django import forms +from django.contrib.auth.forms import AuthenticationForm class LearnerRegistrationForm(forms.Form): @@ -8,6 +9,7 @@ class LearnerRegistrationForm(forms.Form): password = forms.CharField() -class LoginForm(forms.Form): - email = forms.CharField() - password = forms.CharField() +class AuthenticationForm(AuthenticationForm): + + def clean_username(self): + return self.cleaned_data.get('username', '').lower() diff --git a/apps/auth/views.py b/apps/auth/views.py index f6105e75..acb7712d 100644 --- a/apps/auth/views.py +++ b/apps/auth/views.py @@ -7,7 +7,6 @@ from facepy import GraphAPI from facepy.exceptions import FacepyError from django.contrib.auth import get_user_model, logout, login, views -from django.contrib.auth.forms import AuthenticationForm from django.core.files.base import ContentFile from django.http import JsonResponse from django.urls import reverse_lazy @@ -20,7 +19,7 @@ from django.shortcuts import redirect from apps.notification.utils import send_email from apps.config.models import Config -from .forms import LearnerRegistrationForm +from .forms import LearnerRegistrationForm, AuthenticationForm from .tokens import verification_email_token User = get_user_model() @@ -33,7 +32,7 @@ class LearnerRegistrationView(FormView): def form_valid(self, form): first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] - email = form.cleaned_data['email'] + email = form.cleaned_data['email'].lower() password = form.cleaned_data['password'] user, created = User.objects.get_or_create( @@ -170,6 +169,7 @@ class FacebookLoginOrRegistration(View): "errors": {"email": 'is field required'} }) else: + email = email.lower() try: user = User.objects.get(email=email) except User.DoesNotExist: