|
| 1 | +import importlib |
| 2 | + |
1 | 3 | from django.contrib.auth import authenticate
|
2 | 4 | from django.utils.translation import gettext_lazy as _
|
3 | 5 | from rest_framework import exceptions, serializers
|
|
6 | 8 | from .state import User
|
7 | 9 | from .tokens import RefreshToken, SlidingToken, UntypedToken
|
8 | 10 |
|
| 11 | +rule_package, user_eligible_for_login = api_settings.USER_AUTHENTICATION_RULE.rsplit('.', 1) |
| 12 | +login_rule = importlib.import_module(rule_package) |
| 13 | + |
9 | 14 |
|
10 | 15 | class PasswordField(serializers.CharField):
|
11 | 16 | def __init__(self, *args, **kwargs):
|
@@ -42,14 +47,7 @@ def validate(self, attrs):
|
42 | 47 |
|
43 | 48 | self.user = authenticate(**authenticate_kwargs)
|
44 | 49 |
|
45 |
| - # Prior to Django 1.10, inactive users could be authenticated with the |
46 |
| - # default `ModelBackend`. As of Django 1.10, the `ModelBackend` |
47 |
| - # prevents inactive users from authenticating. App designers can still |
48 |
| - # allow inactive users to authenticate by opting for the new |
49 |
| - # `AllowAllUsersModelBackend`. However, we explicitly prevent inactive |
50 |
| - # users from authenticating to enforce a reasonable policy and provide |
51 |
| - # sensible backwards compatibility with older Django versions. |
52 |
| - if self.user is None or not self.user.is_active: |
| 50 | + if not getattr(login_rule, user_eligible_for_login)(self.user): |
53 | 51 | raise exceptions.AuthenticationFailed(
|
54 | 52 | self.error_messages['no_active_account'],
|
55 | 53 | 'no_active_account',
|
|
0 commit comments