List Info

Thread: Re: can anyone give me a simple example of using tools.session_auth with cp3




Re: can anyone give me a simple example of using tools.session_auth with cp3
user name
2007-01-30 10:43:16


On Tue, Jan 16, 2007 at 08:19:24PM +0200, Alex Shteinberg
wrote......

> Yes right on both counts, it works 10x
> >> I have tried to update my working cp2 code and
failed.
> >> a not working version of the cp3 code
> >
> >[snip auth handlers]
> >
> >> class Root:
> >>     _cp_config = {
> >>         'tools.session_auth': True,
> >>         'tools.sessions.on': True,
> >>        
'tools.session_auth.check_username_and_password':
> >> checkLoginAndPassword,
> >>         'tools.session_auth.on_check':
loadUserByUsername,
> >>     }


I read your thread and tried to get this working on CP 3.0
using
this code:

------
import cherrypy

def loadUserByUsername(login):
   
ulist=[("user1","pass1"),("user2&qu
ot;,"pass2")]
    for u,p in ulist:
        if u==login:
            return (u,p)

def checkLoginAndPassword(login, password):
    user = loadUserByUsername(login)
    if user==None:
        return u'Wrong login/password'


class Root:
    _cp_config = {
        'tools.session_auth.on': True,
        'tools.session_auth.check_username_and_password':
checkLoginAndPassword,
        'tools.session_auth.on_check': loadUserByUsername,
    }

    cherrypy.expose
    def index(self):
        return " Hello, you passed auth"

cherrypy.tree.mount(Root())
cherrypy.server.quickstart()
cherrypy.engine.start()
------

However, in my case, it throws the error:

[30/Jan/2007:11:38:30] HTTP Traceback (most recent call
last):
  File
"/usr/lib/python2.4/site-packages/cherrypy/_cprequest.p
y", line 340, in respond
    self.hooks.run('before_handler')
  File
"/usr/lib/python2.4/site-packages/cherrypy/_cprequest.p
y", line 76, in run
    hook()
  File
"/usr/lib/python2.4/site-packages/cherrypy/_cprequest.p
y", line 44, in __call__
    return self.callback(**self.kwargs)
  File
"/usr/lib/python2.4/site-packages/cherrypy/_cptools.py&
quot;, line 138, in _wrapper
    if self.callable(**kwargs):
  File
"/usr/lib/python2.4/site-packages/cherrypy/lib/cptools.
py", line 278, in session_auth
    return sa.run()
  File
"/usr/lib/python2.4/site-packages/cherrypy/lib/cptools.
py", line 271, in run
    return self.do_check()
  File
"/usr/lib/python2.4/site-packages/cherrypy/lib/cptools.
py", line 246, in do_check
    sess = cherrypy.session
AttributeError: 'module' object has no attribute 'session'

Any idea what I'm missing?

Thanks
Kevin

-- 
Kevin Coyner  GnuPG key: 1024D/8CE11941

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users?hl=en

-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )