user.py
 1  from fastapi import status
 2  
 3  from .api_exception import APIException
 4  
 5  
 6  class UserNotFoundError(APIException):
 7      status_code = status.HTTP_404_NOT_FOUND
 8      detail = "User not found"
 9      description = "This user does not exist."
10  
11  
12  class UserAlreadyExistsError(APIException):
13      status_code = status.HTTP_409_CONFLICT
14      detail = "User already exists"
15      description = "This user already exists."
16  
17  
18  class MFAAlreadyEnabledError(APIException):
19      status_code = status.HTTP_409_CONFLICT
20      detail = "MFA already enabled"
21      description = "MFA is already enabled."
22  
23  
24  class MFANotInitializedError(APIException):
25      status_code = status.HTTP_412_PRECONDITION_FAILED
26      detail = "MFA not initialized"
27      description = "MFA has not been initialized."
28  
29  
30  class InvalidCodeError(APIException):
31      status_code = status.HTTP_412_PRECONDITION_FAILED
32      detail = "Invalid code"
33      description = "This mfa code is invalid or has expired."
34  
35  
36  class MFANotEnabledError(APIException):
37      status_code = status.HTTP_412_PRECONDITION_FAILED
38      detail = "MFA not enabled"
39      description = "MFA is not enabled."
40  
41  
42  class NoLoginMethodError(APIException):
43      status_code = status.HTTP_412_PRECONDITION_FAILED
44      detail = "No login method"
45      description = "No login method was provided."
46  
47  
48  class CannotDeleteLastLoginMethodError(APIException):
49      status_code = status.HTTP_403_FORBIDDEN
50      detail = "Cannot delete last login method"
51      description = "The last login method (password or oauth connection) cannot be deleted."
52  
53  
54  class RegistrationDisabledError(APIException):
55      status_code = status.HTTP_403_FORBIDDEN
56      detail = "Registration disabled"
57      description = "Registration is disabled."
58  
59  
60  class OAuthRegistrationDisabledError(APIException):
61      status_code = status.HTTP_403_FORBIDDEN
62      detail = "OAuth Registration disabled"
63      description = "OAuth Registration is disabled."
64  
65  
66  class RecaptchaError(APIException):
67      status_code = status.HTTP_412_PRECONDITION_FAILED
68      detail = "Recaptcha failed"
69      description = "The ReCaptcha response is invalid."