Prevent unapproved users logging in through embeds

Test suite doing its job...!
This commit is contained in:
2020-01-11 19:25:50 +00:00
parent 4d722fd5cb
commit ea12bfa607

View File

@@ -34,8 +34,15 @@ class ProfileRegistrationFormUniqueEmail(RegistrationFormUniqueEmail):
return self.cleaned_data['initials']
class CheckApprovedForm(AuthenticationForm):
def confirm_login_allowed(self, user):
if not user.is_approved and not user.is_superuser:
raise forms.ValidationError("Your account hasn't been approved by an administrator yet. Please check back in a few minutes!")
return AuthenticationForm.confirm_login_allowed(self, user)
# Embedded Login form - remove the autofocus
class EmbeddedAuthenticationForm(AuthenticationForm):
class EmbeddedAuthenticationForm(CheckApprovedForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs.pop('autofocus', None)
@@ -55,13 +62,6 @@ class ProfileChangeForm(UserChangeForm):
model = models.Profile
class CheckApprovedForm(AuthenticationForm):
def confirm_login_allowed(self, user):
if not user.is_approved and not user.is_superuser:
raise forms.ValidationError("Your account hasn't been approved by an administrator yet. Please check back in a few minutes!")
return AuthenticationForm.confirm_login_allowed(self, user)
# Events Shit
class EventForm(forms.ModelForm):
datetime_input_formats = formats.get_format_lazy("DATETIME_INPUT_FORMATS") + list(settings.DATETIME_INPUT_FORMATS)