From fe4edb2205ae271d262a18308735b4b166ecce21 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Mon, 18 Sep 2023 18:59:37 +0100 Subject: [PATCH] raise validation errors --- backend/api/forms.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/api/forms.py b/backend/api/forms.py index 2d82ac5..ca4ecee 100644 --- a/backend/api/forms.py +++ b/backend/api/forms.py @@ -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()} @@ -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