Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] error message for is_active=False user #160

Open
tonypottera24 opened this issue Jun 25, 2022 · 2 comments
Open

[FEATURE] error message for is_active=False user #160

tonypottera24 opened this issue Jun 25, 2022 · 2 comments

Comments

@tonypottera24
Copy link

tonypottera24 commented Jun 25, 2022

Does anyone know how to extend the APIVIew to return more accurate messages for is_active=False users?

@duranbe
Copy link

duranbe commented Dec 19, 2022

from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view()
def hello_world(request):
    if request.user.is_active:
        return Response({"message": "Hello, world!"})
    
   return Response({"message": "Not hello, world!"})
    

?

@Fireclunge
Copy link

Fireclunge commented Dec 24, 2023

This library for some reason decides that if a user isn't active it just won't ever send an email out and it does this by monkey patching the user model to expose a new function

I don't know if this is the best or most elegant fix, but you can monkey patch it back out. A env setting to allow inactive users to have password resets would be so much better.

# django_rest_passwordreset_override.py
# Override for django-rest-passwordreset
from django.conf import settings
from django.contrib.auth import get_user_model


def override_password_reset():
    # add eligible_for_reset to the user class
    UserModel = get_user_model()
    UserModel.add_to_class("eligible_for_reset", eligible_for_reset)


def eligible_for_reset(self):
    if getattr(settings, 'DJANGO_REST_MULTITOKENAUTH_REQUIRE_USABLE_PASSWORD', True):
        # if we require a usable password then return the result of has_usable_password()
        return self.has_usable_password()
    else:
        # otherwise return True because we dont care about the result of has_usable_password()
        return True
# urls.py
# call this after importing the rest urls 
override_password_reset()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants