Let me just add one more. Make a superclass that handles the auth part
in __init__ and subclass your controller classes.

On Mon, Jun 13, 2011 at 2:08 AM, Franck <[email protected]> wrote:
> Hi John,
> I suppose you could use an "application processor" : basically it could be
> written once and check the user before each request
> http://webpy.org/cookbook/application_processors
> There are other ways, though, like wrapping each GET/POST with a Python
> decorator : see this for instance (needs to be adjusted to your needs
> though) :
> http://pastebin.com/Stn9uKvH
> Besides, maybe Apache could handle authentication for you ?
> Cheers
> Franck
> On Sun, Jun 12, 2011 at 4:44 PM, John Fulton <[email protected]> wrote:
>>
>> I have a web.py application where, if I authenticate user, then I set a
>> session, and then use that session to determine if the user is logged in.
>> The problem is that I'm breaking DRY by checking the status of the session
>> within the definition of each class that corresponds to any URL that user
>> might use. There is probably a better way to do this. Can anyone on the list
>> offer some advice?
>>
>> Thanks,
>>  John
>>
>> class foo:
>>    def GET(self):
>>        if (len(session.username) == 0):
>>            raise web.seeother('/login')
>>        foo = db.select('foo')
>>        return render.foo(foo)
>>
>> class bar:
>>    def GET(self):
>>        if (len(session.username) == 0):
>>            raise web.seeother('/login')
>>        return render.bar()
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "web.py" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email
>> to [email protected].
>> For more options, visit this group
>> at http://groups.google.com/group/webpy?hl=en.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/webpy?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to