Did i miss something ot the following would be ok ?

    def requires_login(self, next=None, message=self.message.access_denied
):
        """
        decorator that prevents access to action if not logged in
        """

        def decorator(action):

            def f(*a, **b):

                if not self.basic() and not self.is_logged_in():
                    request = self.environment.request
                    self.environment.session.flash = message
                    if not next:
                        next = self.settings.login_url + '?_next=' + \

 urllib.quote(URL(r=request,args=request.args,
                                vars=request.get_vars))
                    redirect(next)
                return action(*a, **b)
            f.__doc__ = action.__doc__
            f.__name__ = action.__name__
            f.__dict__.update(action.__dict__)
            return f

        return decorator



On Tue, May 25, 2010 at 01:07, Massimo Di Pierro <[email protected]>wrote:

> It would be nice to be able to pass the following arguments to
>
> @auth.requires_login(next=URL(...),message=T(...))
>
> where next is the url to redirect to in case of no login. message is the
> message to be displayed.
> If somebody has time and wants to take a crack at it, let me know. It
> should be possible by modifying only the requires_login method.
> The problem is passing the arguments from the decorator to the function
> being returned.
>
> Once the problem is solved we can add the feature to requires_membership
> and requires_permissions.
>
> Massimo
>

Reply via email to