tags:

views:

52

answers:

1

I am using Django.

How can i kick off a user who has logged-in?

or

How can i get the user's session and kill it?

A: 

If you can access the shell, then:

$ ./manage.py shell

In [1]: from django.contrib.sessions.models import Session

In [2]: for s in Session.objects.all():
   ...:     data = s.get_decoded()
   ...:     if data.get('_auth_user_id', None) == YOUR_USER_ID:
   ...:         s.delete()
   ...:         
   ...:         

Replace YOUR_USER_ID with the ID of a user to be kicked.

The key '_auth_user_id' may differ from version to version, I suppose, but that worked for me. To check if you have the same, just print out some of s.get_decoded() and look at the output.

d.m
Oh, haven't noticed the comment from John…
d.m