[mod_python] Authorization problem

Graham Dumpleton graham.dumpleton at gmail.com
Mon Feb 4 17:15:02 EST 2008


It would help if you told us what you expected to happen and what
actually happens, including any errors. Most people aren't going to
want to take your code and actually run it to try and work that out.
Even doing this might be hard anyway as one would have to assume how
you expected it to work. So, we can assist you in debugging it for
yourself, but you will need to explain the problem properly.

Graham

On 05/02/2008, vytas dvaras <dvaras at lycos.com> wrote:
> Hello everyone,
>
> I was trying to do an application with mod_python, that allows to use it's
> resources only to logged in users:
>
> I have:
> 1. One html page with login, password input fields and a submit button.
> 2. python script (that uses mod_python) and does something
>
> I would like to do so, that if the user is not logged in - he/she is
> redirected back to login page each time she/he tries to access any function
> without logging in.
>
>
> I used the example #1 from:
> http://wiki.apache.org/mod_python/Session_use_with_classes?highlight=%28CategoryExamples%29
>
> The problem is that my script "enhancements" don't work as expected. I was
> trying to solve this problem for some time, but at last I came to a
> conclusion that a help from somebody else is really needed :)
>
> index.html:
>
>
>
>
>
>
>
>
>
>
>
>  Login:
>
>
>  Password:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _sessions.py:
> from mod_python import apache, util, Session
>
> def handler(req):
>  #login = req.form.getfirst('vardas') #this does't work here
>
>  # but I would like to make a session after I authenticate a user
>  if not hasattr(req, 'session'):
>  req.session = Session.Session(req)
>  return apache.OK
>
>
> aha.py:
> from mod_python import apache, util, Session
> from time import time
>
> _tags = (1,2,3,4)
>
> class ExampleSession:
>  def __call__(self, req):
>
>  # these lines work, but the session IS allready created
>  login = req.form.getfirst('vardas')
>  passw = req.form.getfirst('slaptazodis')
>
>  if login != 'testas' or passw != '007':
>  util.redirect(req, '../index.html')
>
>  # these work in _session.py, but don't work here
> # if not hasattr(req, 'session'):
> # util.redirect(req, '../index.html')
>  return self._foo(req)
>
>
>  def __init__(self, *args, **kwargs):
>  # Do something with the args here.
>  return
>
>
>  def _foo(self, req):
>
>  try:
>  delta = int(time()- req.session['last'])
>  except KeyError:
>  delta = 0
>  total = int(time()- req.session.created())
>  try:
>  req.session['hits'] += 1
>  except:
>  req.session['hits'] = 1
>
>  req.session['last'] = req.session.last_accessed()
>  req.session.save()
>  return """Session ID: %s
> This session has been active for %d seconds
> This session was last accessed %d seconds ago
> This session has been accessed %d times
> """ % \
>  (req.session.id(), total, delta, req.session['hits'], 'login', 'passw')
>
> foo = ExampleSession(_tags)
>
>
>
> What am I doing wrong? I can't find any better working examples and I have
> allready read everything I found relating to my problem. So if you have any
> ideas or examples it would be great to have a look at them.
>
> Regards,
> Vytas
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>


More information about the Mod_python mailing list