Skip to content

Commit a0c7541

Browse files
Use IMPORT_STRINGS for auth rule (jazzband#336)
* Applied lint Co-authored-by: Andrew-Chen-Wang <acwangpython@gmail.com> Co-authored-by: David Sanders <davesque@gmail.com>
1 parent 148a2e3 commit a0c7541

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

rest_framework_simplejwt/serializers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import importlib
2-
31
from django.contrib.auth import authenticate, get_user_model
42
from django.contrib.auth.models import update_last_login
53
from django.utils.translation import gettext_lazy as _
@@ -8,9 +6,6 @@
86
from .settings import api_settings
97
from .tokens import RefreshToken, SlidingToken, UntypedToken
108

11-
rule_package, user_eligible_for_login = api_settings.USER_AUTHENTICATION_RULE.rsplit('.', 1)
12-
login_rule = importlib.import_module(rule_package)
13-
149

1510
class PasswordField(serializers.CharField):
1611
def __init__(self, *args, **kwargs):
@@ -47,7 +42,7 @@ def validate(self, attrs):
4742

4843
self.user = authenticate(**authenticate_kwargs)
4944

50-
if not getattr(login_rule, user_eligible_for_login)(self.user):
45+
if not api_settings.USER_AUTHENTICATION_RULE(self.user):
5146
raise exceptions.AuthenticationFailed(
5247
self.error_messages['no_active_account'],
5348
'no_active_account',

rest_framework_simplejwt/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
IMPORT_STRINGS = (
4343
'AUTH_TOKEN_CLASSES',
4444
'TOKEN_USER_CLASS',
45+
'USER_AUTHENTICATION_RULE',
4546
)
4647

4748
REMOVED_SETTINGS = (

0 commit comments

Comments
 (0)