Skip to content

Commit

Permalink
raise validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 18, 2023
1 parent 78f5ef0 commit fe4edb2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion backend/api/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def __init__(self, request: WSGIRequest, *args, **kwargs):
super().__init__(*args, **kwargs)

def clean(self):
if self.errors:
raise ValidationError(
"Found form errors. Skipping authentication.",
code="form_errors",
)

self.user = authenticate(
self.request,
**{key: self.cleaned_data[key] for key in self.fields.keys()}
Expand All @@ -23,7 +29,11 @@ def clean(self):
self.get_invalid_login_error_message(),
code="invalid_login",
)
# TODO: confirm if we should return error message if is_active=False
elif not self.user.is_active:
raise ValidationError(
"User is not active",
code="user_not_active",
)

return self.cleaned_data

Expand Down

0 comments on commit fe4edb2

Please sign in to comment.