I want to restrict multiple logins for which i want to access request.user.is_authenticated attribute , i tried to access this attribute in the middlewares in the response cycle when login view call has been made but still in both the cycles like from request to response and back this attricute is false , so needs help
my models.py
class LoggedInUser(models.Model):
user = models.ForeignKey(User, related_name='logged_in_user', on_delete =models.CASCADE, null=True, blank=True)
session_key = models.OneToOneField(Session, on_delete=models.CASCADE, null=True, blank=True)
def __str__(self):
return self.user.username
my signals.py
@receiver(user_logged_in)
def delete_other_active_sessions(sender, user, request, **kwargs):
Session.objects.filter(loggedinuser__user=user).delete()
print('here inside signals')
#save current session
request.session.save()
LoggedInUser.objects.get_or_create(user=user, session = request.session.session_key)
user_logged_in.connect(delete_other_active_sessions)
my apps.py
class AccountsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "accounts"
def ready(self):
import accounts.signals
This is how i am trying to restrict multiple logins but signals are not fired needs help