Home > OS >  How can i check to see if a user is active using signals in django
How can i check to see if a user is active using signals in django

Time:02-17

Im trying to implement an online and offline functionality in my app in django and can't work out how to check to see if a user is logged in and active or offline and inactive in my app can anyone help me with implementing it please.

CodePudding user response:

Here is the code how you can send signals for user.is_active. You have to import user model.

from django.contrib.auth.models import User


@receiver(post_save, sender=User)
def check_active_user(sender, instance, **kwargs):
    if instance.is_active:
       .... your code 

CodePudding user response:

the logic should be writin in the application while its working i can give you couple of tips to get that logic:- you can ping google or any site to check the network then in condition at if condition if the ping is not getting anything , you can pass the update in the database that user is not active or logout , if you mean to check if active in the database , you could use login if form.is_valid() to write all the condition you want ,

  • Related