11import warnings
2- from typing import Any , Callable , Dict , Optional , Type , Union , cast
2+ from typing import Any , Callable , Dict , Optional , Type , cast
33
44from django .conf import settings
55from django .contrib .auth import authenticate , get_user_model
@@ -46,11 +46,11 @@ class TokenInputSchemaMixin(InputSchemaMixin):
4646 "no_active_account" : _ ("No active account found with the given credentials" )
4747 }
4848
49- @ classmethod
50- def check_user_authentication_rule (
51- cls , user : Optional [ Union [ AbstractUser , Any ]], values : Dict
52- ) -> bool :
53- return api_settings . USER_AUTHENTICATION_RULE ( user )
49+ def check_user_authentication_rule ( self ) -> None :
50+ if not api_settings . USER_AUTHENTICATION_RULE ( self . _user ):
51+ raise exceptions . AuthenticationFailed (
52+ self . _default_error_messages [ "no_active_account" ]
53+ )
5454
5555 @classmethod
5656 def validate_values (cls , values : Dict ) -> dict :
@@ -71,14 +71,13 @@ def validate_values(cls, values: Dict) -> dict:
7171 raise exceptions .ValidationError ({"password" : "password is required" })
7272
7373 _user = authenticate (** values )
74+ cls ._user = _user
7475
75- if not cls . check_user_authentication_rule ( _user , values ) :
76+ if _user is None :
7677 raise exceptions .AuthenticationFailed (
7778 cls ._default_error_messages ["no_active_account" ]
7879 )
7980
80- cls ._user = _user
81-
8281 return values
8382
8483 def output_schema (self ) -> Schema :
@@ -117,6 +116,7 @@ def post_validate_schema(cls, values: Dict) -> dict:
117116 :return:
118117 """
119118 # get_token can return values that wants to apply to `OutputSchema`
119+
120120 data = cls .get_token (cls ._user )
121121
122122 if not isinstance (data , dict ):
0 commit comments