def is_authenticated(self, request, **kwargs):
from django.contrib.sessions.models import Session
if 'sessionid' in request.COOKIES:
try:
s = Session.objects.get(pk=request.COOKIES['sessionid'])
except Exception,e:
logger.warning("user with sessionid : %s not found" % request.COOKIES['sessionid'])
return False
# get the user_id from the session
if '_auth_user_id' in s.get_decoded():
# try to find the user associated with the given sessionid
try:
u = User.objects.get(pk=s.get_decoded()['_auth_user_id'])
if u is not None:
return True
except Exception,e:
return False
else:
return False
else:
logger.warning("sessionid is missing in the request")
return False