Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 28, 2011 22:50:21

Brian C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

standalone session checking


I'm trying to implement a stand-alone python script to check a session
cookie for group authorization. I cribbed from the auth and session
middleware, so I could take the sessionid from the cookie, look up the
session, look up the user, and get the list of groups.

This all basically works, except for the very first time a session is
seen. The first lookup always fails. I know the session is good (a
call to a django view via @login_required, for example, works fine).

I'm expecting this is some problem with a cache, or evaluation order,
such that my script doesn't have the latest info from the db until
I've queried it once. Anyone have a clue? Here's what the auth
checking routine looks like:


def authorized(session_id, group):
ss = engine.SessionStore(session_id)
session=ss.load()
try:
user_id = session
backend_path = session
backend = load_backend(backend_path)
user = backend.get_user(user_id) or AnonymousUser()
except KeyError:
user = AnonymousUser()
return user.groups.filter(name=group).count()


It's called from a "while 1" loop in a script that never exits. The
first time a session cookie goes through this routine, it always
fails. Second, and subsequent times work.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 21st of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support