2023-09-29 16:07:45 +00:00
|
|
|
from django.contrib.auth.forms import AuthenticationForm
|
|
|
|
from django.contrib.auth import authenticate
|
|
|
|
|
|
|
|
|
|
|
|
class LoginForm(AuthenticationForm):
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
username = self.cleaned_data.get('username')
|
|
|
|
password = self.cleaned_data.get('password')
|
|
|
|
|
|
|
|
if not (username and password):
|
|
|
|
raise self.get_invalid_login_error()
|
|
|
|
|
|
|
|
user = authenticate(username=username, password=password)
|
|
|
|
|
2023-10-02 15:49:33 +00:00
|
|
|
if user is None:
|
2023-09-29 16:07:45 +00:00
|
|
|
raise self.get_invalid_login_error()
|
|
|
|
|
|
|
|
return self.cleaned_data
|
|
|
|
|