anexia-it / django-rest-passwordreset

An extension of django rest framework, providing a configurable password reset strategy
BSD 3-Clause "New" or "Revised" License
419 stars 148 forks source link

unable to enter into function password_reset_token_created function by generating signal #46

Closed surajraktate closed 5 years ago

surajraktate commented 5 years ago

from django.dispatch import receiver from django.template.loader import render_to_string from django.urls import reverse from django_rest_passwordreset.signals import reset_password_token_created, pre_password_reset, \ post_password_reset

from sixwallz_app import config from sixwallz_app.send_invitaion_mail import * import logging

log = logging.getLogger(name)

@receiver(reset_password_token_created) def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs): """ Handles password reset tokens When a token is created, an e-mail needs to be sent to the user :param sender: View Class that sent the signal :param instance: View Instance that sent the signal :param reset_password_token: Token Model Object :param args: :param kwargs: :return: """ print("Write Something")

send an e-mail to the user

context = {
    'current_user': reset_password_token.user,
    'username': reset_password_token.user.username,
    'email': reset_password_token.user.email,
    'reset_password_url': "{}?token={}".format(reverse('password_reset:reset-password-request'),
                                               reset_password_token.key)
}
anx-ckreuzberger commented 5 years ago

Which version of the library are you using? Which version of Django and Django Rest Framework?

Did you include the library in INSTALLED_APPS?

Samirovich commented 5 years ago

Hi i can confirm, the signal reset_password_token_created is not being triggered/received. Tried using Django 2.1.8 and DRF 3.9.4.

anx-ckreuzberger commented 5 years ago

I just checked my django app, which is running

and it is working fine.

I just double checked the tests (we have a test that checks that the signal is triggered) and it is working.

Please provide more information about which version of django-rest-passwordreset you are using (e.g., by showing the output of pip freeze).

Also, if you are using

@receiver(reset_password_token_created)
def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs):

you NEED to use verison 1.0.0 (or later), it will not work with 0.9.7 or below.

alexandrebarbaruiva commented 5 years ago

Same issue, I'm using

Django==1.10.6
django-celery==3.2.2
django-cors-headers==2.1.0
django-filter==1.1.0
django-nose==1.4.6
django-rest-passwordreset==1.0.0
django-rest-swagger==2.1.2
django-sendgrid-webhook==0.3.0
djangorestframework==3.6.1
tukhfatov commented 5 years ago

Hi, I had the same issue, but I was able to resolved it. Please check the link below: How to create Django signals Make sure that you imported your signal in app.py and use your new configs in init.py.

Happy coding.

anx-ckreuzberger commented 5 years ago

@tukhfatov Thank you for the information, that could indeed be the cause! IMHO this is actually one of the main obstacles that one can hit when developing a django application.

To re-iterate the comment, this is what it means:

Defining a function with the annotation @receiver(reset_password_token_created) is not enough, you also need to make sure that this particular part of the python code is actually executed/reached. Therefore his suggestion is

Make sure that you imported your signal in app.py and use your new configs in init.py.

works fine - see section "Where Should the Code Live?" in the link from above ( https://simpleisbetterthancomplex.com/tutorial/2016/07/28/how-to-create-django-signals.html ).

Another "trick" (although the approach is undoubtably not very clean) is to put the whole function into your models.py or views.py, as these two files are always loaded and executed by Django itself.

@surajraktate @alexandrebarbaruiva @Samirovich Please report if this fixes your issue.

I will make sure that this gets added to the documentation, maybe even with a FAQ section.

zOthix commented 3 years ago

Hi i am using development server and this still isnt working, i have the signals file by initializing it in apps.py of my application, also initialized apps.py in init file of my application, yet the signal is still not fired, i am using the latest version of the library

amsfwd commented 2 years ago

Request to reopen because I can reproduce this in django 3.2 even when following the instructions provided.

awaistkd commented 2 years ago

@amsfwd It's a known issue. Please have a look at the documentation for the solution. https://github.com/anexia-it/django-rest-passwordreset#the-reset_password_token_created-signal-is-not-fired

I fixed this issue by putting the receiver function in the models.py file.