Skip to content

Commit

Permalink
Fix the problem with allauth (#265)
Browse files Browse the repository at this point in the history
Using with allauth and `is_active` of a user is set to False, it tries
to return the `account_inactive` html template which does not exist.
  • Loading branch information
taiki-okano committed Jun 2, 2021
1 parent 007e46e commit 7dc50bd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dj_rest_auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
from django.contrib.auth.tokens import default_token_generator
from django.urls import exceptions as url_exceptions
from django.utils.encoding import force_str
from django.utils.http import urlsafe_base64_decode as uid_decoder
from django.utils.module_loading import import_string


try:
from django.utils.translation import gettext_lazy as _
except ImportError:
Expand All @@ -17,7 +17,6 @@

from .models import TokenModel


# Get the UserModel
UserModel = get_user_model()

Expand Down Expand Up @@ -96,7 +95,14 @@ def get_auth_user(self, username, email, password):
else `None` will be returned
"""
if 'allauth' in settings.INSTALLED_APPS:
return self.get_auth_user_using_allauth(username, email, password)

# When `is_active` of a user is set to False, allauth tries to return template html
# which does not exist. This is the solution for it. See issue #264.
try:
return self.get_auth_user_using_allauth(username, email, password)
except url_exceptions.NoReverseMatch:
msg = _('Unable to log in with provided credentials.')
raise exceptions.ValidationError(msg)
return self.get_auth_user_using_orm(username, email, password)

@staticmethod
Expand Down

1 comment on commit 7dc50bd

@TheSinghsDen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taiki-okano @iMerica When using allauth how can we show the proper error message that an account is inactive. We do have a check later on that explicitly checks for the user "active" status, but the code never reaches there. Issue #387 has highlighted this in more details.

Please sign in to comment.