How to log out a user

28 views
Skip to first unread message

Torsten Bronger

unread,
Aug 12, 2014, 2:33:26 PM8/12/14
to django...@googlegroups.com
Hallöchen!

I know that there is a logout(request) routine, but how to program a
logout(user) routine?

Background: Every night, a cronjob iterates over all active users
in our Django deployment and checks whether they can still be found
in our LDAP directory. Every user that is not found anymore is set
to inactive. Unfortunately, this is not enough, he or she must be
logged out. But how to do that?

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten...@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.com

François Schiettecatte

unread,
Aug 12, 2014, 2:44:38 PM8/12/14
to django...@googlegroups.com
You should take a look at sessions:

https://docs.djangoproject.com/en/1.7/topics/http/sessions/

You can arbitrarily remove sessions regardless of expiration which will log out the user.

François
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/87egwlk18f.fsf%40physik.rwth-aachen.de.
> For more options, visit https://groups.google.com/d/optout.

Nikolas Stevenson-Molnar

unread,
Aug 12, 2014, 3:05:24 PM8/12/14
to django...@googlegroups.com
Unfortunately, you can't look up sessions by user, so you've have to
load every active session and see if its for the user you wish to
logout. Alternatively, you could create your own mapping of users to
sessions, or add some middleware that verifies the user is active on
every request, and signs them out if not (so the logout wouldn't happen
during the cron job, but rather the first time they try to access the
site after being marked inactive).

_Nik
Reply all
Reply to author
Forward
0 new messages