29 lines
950 B
Python
29 lines
950 B
Python
from django.contrib.auth.forms import AuthenticationForm
|
|
from django.contrib.auth.models import User
|
|
|
|
from .authentications import authentication
|
|
|
|
|
|
class LoginForm(AuthenticationForm):
|
|
def clean(self):
|
|
username = self.cleaned_data.get("username")
|
|
password = self.cleaned_data.get("password")
|
|
|
|
if username is not None and password:
|
|
auth_user = authentication(username, password)
|
|
|
|
if auth_user:
|
|
try:
|
|
self.user_cache = User.objects.get(username=auth_user.lower())
|
|
except User.DoesNotExist:
|
|
self.user_cache = User.objects.create_user(auth_user.lower())
|
|
else:
|
|
raise self.get_invalid_login_error()
|
|
|
|
if self.user_cache is None:
|
|
raise self.get_invalid_login_error()
|
|
else:
|
|
self.confirm_login_allowed(self.user_cache)
|
|
|
|
return self.cleaned_data
|