I want to have something like user controller in default.py.
def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    """
    return dict(form=auth())

So i would like to have:
def item():
     """
     http://..../[app]/default/item/list
     http://..../[app]/default/item/add_product
     """
     return dict(form=product())

And when user invoke url for add_product, the request should be rejected if 
not login yet, i though i just decorate the add_product function in module 
with @auth.
I think i should try your suggestion to check for the auth beforehand and 
invoke the proper method of Product class.

On Monday, April 15, 2013 1:03:49 AM UTC+9, Anthony wrote:
>
> Can you show the code where you are calling the add_product() method? 
> Using the @auth.requires_login() decorator is not the only way to control 
> access. You can also do "if auth.user:" to test for login before allowing a 
> method to be called.
>
> Anthony
>
> On Sunday, April 14, 2013 7:06:15 AM UTC-4, Reza Shah wrote:
>>
>> Hi,
>>
>> I'm learning web2py and i want to put my business logic inside a class in 
>> module.
>> I like to have a behaviour similar to user controller inside default.py 
>> which exposes several functions.
>>
>> I have a controller item which i put inside default.py
>> def item():
>>      return dict(form=product())
>>
>> in module i create product class
>>
>> class Product(object):
>>      def __init__:
>>
>>      def list(self):
>>
>>      @auth.requires_login()
>>      def add_product(self):
>>
>> The Product.list function can be accessed by anyone, but for adding new 
>> product need user login first.
>> Is this possible? 
>> Does the auth can used directly or i need to import something first?
>>
>> Thank,
>> Reza
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to