0

I have a receiver for post_save signal that detects and restricts multiple active access tokens from the same user.

In addition to this, I want to lock that detected user for a minute and reactivate the user once again by using the is_active field of the user.

Is there a way to do this without creating and using a new model to store the start time of the account lock? Also, I think making a scheduled job for this is a bit overkill.

Castle
  • 85
  • 1
  • 7

1 Answers1

0

Using Django celery, I managed to set up an async task to solve my problem.

@app.task
def start_timeout(username):

    from time import sleep
    from django.contrib.auth.models import User

    user_obj = User.objects.get(username=username)
    user_obj.is_active = False
    user_obj.save()
    sleep(60)
    user_obj.is_active = True
    user_obj.save()
Castle
  • 85
  • 1
  • 7