Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
can anyone give me a simple example of using tools.session_auth with cp3
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Hal  
View profile  
 More options Jan 16 2007, 11:24 am
From: "Hal" <alex.sht...@gmail.com>
Date: Tue, 16 Jan 2007 16:24:30 -0000
Local: Tues, Jan 16 2007 11:24 am
Subject: can anyone give me a simple example of using tools.session_auth with cp3
I have tried to update my working cp2 code and failed.
Here is a simplified version of my working cp2 code:

####  start
import cherrypy

def loadUserByUsername(login):
    ulist=[("user1","pass1"),("user2","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'

settings={ 'global':{
                 'session_authenticate_filter.on': True,
                 'session_filter.on':True,
            },
            '/': {
                'session_authenticate_filter.check_login_and_password':
checkLoginAndPassword,
                'session_authenticate_filter.load_user_by_username':
loadUserByUsername,
            },

}

cherrypy.config.update(settings)

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

cherrypy.root=Root()
cherrypy.server.start()

### end
and a not working version of the cp3 code

### start
import cherrypy

def loadUserByUsername(login):
    ulist=[("user1","pass1"),("user2","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': True,
        'tools.sessions.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()
### end


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Wyglendowski  
View profile  
 More options Jan 16 2007, 11:38 am
From: "Christian Wyglendowski" <christ...@dowski.com>
Date: Tue, 16 Jan 2007 11:38:40 -0500
Local: Tues, Jan 16 2007 11:38 am
Subject: Re: [cherrypy-users] can anyone give me a simple example of using tools.session_auth with cp3
On 1/16/07, Hal <alex.sht...@gmail.com> wrote:

> I have tried to update my working cp2 code and failed.

[snip cp2 version]

> 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,
>     }

Possible problem #1: maybe it should be tools.session_auth.on = True?

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

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

Possible problem #2: It should probably be
cherrypy.tree.mount(Root()), or you could do
cherrypy.quickstart(Root()).

HTH,

Christian


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Shteinberg  
View profile  
 More options Jan 16 2007, 1:19 pm
From: "Alex Shteinberg" <alex.sht...@gmail.com>
Date: Tue, 16 Jan 2007 20:19:24 +0200
Local: Tues, Jan 16 2007 1:19 pm
Subject: Re: [cherrypy-users] Re: can anyone give me a simple example of using tools.session_auth with cp3

Yes right on both counts, it works 10x

On 1/16/07, Christian Wyglendowski <christ...@dowski.com> wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Coyner  
View profile  
 More options Jan 30 2007, 11:43 am
From: Kevin Coyner <ke...@rustybear.com>
Date: Tue, 30 Jan 2007 11:43:16 -0500
Local: Tues, Jan 30 2007 11:43 am
Subject: Re: [cherrypy-users] Re: can anyone give me a simple example of using tools.session_auth with cp3

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","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.py", line 340, in respond
    self.hooks.run('before_handler')
  File "/usr/lib/python2.4/site-packages/cherrypy/_cprequest.py", line 76, in run
    hook()
  File "/usr/lib/python2.4/site-packages/cherrypy/_cprequest.py", line 44, in __call__
    return self.callback(**self.kwargs)
  File "/usr/lib/python2.4/site-packages/cherrypy/_cptools.py", 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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Brewer  
View profile  
 More options Jan 30 2007, 12:17 pm
From: "Robert Brewer" <fuman...@amor.org>
Date: Tue, 30 Jan 2007 09:17:13 -0800
Local: Tues, Jan 30 2007 12:17 pm
Subject: RE: [cherrypy-users] Re: can anyone give me a simple example of using tools.session_auth with cp3

Because sessions are an extension to CherryPy (and not a builtin), there
will be no "cehrrypy.session" object unless you either 1) turn on
tools.sessions, or 2) do it yourself by calling lib.sessions.init and
friends.

Robert Brewer
System Architect
Amor Ministries
fuman...@amor.org


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Coyner  
View profile  
 More options Jan 30 2007, 12:32 pm
From: Kevin Coyner <ke...@rustybear.com>
Date: Tue, 30 Jan 2007 12:32:12 -0500
Local: Tues, Jan 30 2007 12:32 pm
Subject: Re: [cherrypy-users] Re: can anyone give me a simple example of using tools.session_auth with cp3

On Tue, Jan 30, 2007 at 09:17:13AM -0800, Robert Brewer wrote......
> Because sessions are an extension to CherryPy (and not a builtin),
> there will be no "cehrrypy.session" object unless you either 1)
> turn on tools.sessions, or 2) do it yourself by calling
> lib.sessions.init and friends.

Thanks.  That did the trick.  For those like me who have struggled with some of
these things, below you will find a working code example for CP 3.0:

-----
import cherrypy

def loadUserByUsername(login):
    ulist=[("user1","pass1"),("user2","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.sessions.on': True,
        '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()
-----

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google