Skip to content

Commit

Permalink
Use IMPORT_STRINGS for auth rule (jazzband#336)
Browse files Browse the repository at this point in the history
* Applied lint

Co-authored-by: Andrew-Chen-Wang <acwangpython@gmail.com>
Co-authored-by: David Sanders <davesque@gmail.com>
  • Loading branch information
davesque and Andrew-Chen-Wang authored Nov 23, 2020
1 parent 148a2e3 commit a0c7541
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
7 changes: 1 addition & 6 deletions rest_framework_simplejwt/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import importlib

from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth.models import update_last_login
from django.utils.translation import gettext_lazy as _
Expand All @@ -8,9 +6,6 @@
from .settings import api_settings
from .tokens import RefreshToken, SlidingToken, UntypedToken

rule_package, user_eligible_for_login = api_settings.USER_AUTHENTICATION_RULE.rsplit('.', 1)
login_rule = importlib.import_module(rule_package)


class PasswordField(serializers.CharField):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -47,7 +42,7 @@ def validate(self, attrs):

self.user = authenticate(**authenticate_kwargs)

if not getattr(login_rule, user_eligible_for_login)(self.user):
if not api_settings.USER_AUTHENTICATION_RULE(self.user):
raise exceptions.AuthenticationFailed(
self.error_messages['no_active_account'],
'no_active_account',
Expand Down
1 change: 1 addition & 0 deletions rest_framework_simplejwt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
IMPORT_STRINGS = (
'AUTH_TOKEN_CLASSES',
'TOKEN_USER_CLASS',
'USER_AUTHENTICATION_RULE',
)

REMOVED_SETTINGS = (
Expand Down

0 comments on commit a0c7541

Please sign in to comment.