Aha! I'm glad you said this.

I tried out your tests above, and they did indeed work.

The difference between those and my function in the initial post that
did not work is that test1 returns a string directly, and the test
index() above returns a dictionary, like in the auth tutorial:
@auth.requires_login()
def index():
    """
    Login-protected index page
    """
    response.flash = str(request.vars)
    return dict(form=auth())

When you pass an arg to an auth-protected function that returns dict
(form=auth()), that arg results in a 404. (And the vars just get
dropped).
But if I don't return form=auth(), then the function is not actually
auth-protected, and does not prompt for login, etc.

So, can you try that?


On Sep 30, 5:57 pm, mdipierro <[email protected]> wrote:
> Sorry, I did not mean to say I do not believe you.
> I meant to say that either I do not understand the question or
> something else is going on in your code.
>
> I just did the following test:
>
> a new app
>
> def test1: return repr(dict(request.vars))
>
> @auth.requires_login()
> def test2: return repr(dict(request.vars))
>
> and then logged in and 
> visitedhttp://..../test1?hello=worldhttp://..../test2?hello=world
>
> They both show
>
> {'hello': 'world'}
>
> If this does not work for you then there is a major problem but it is
> not in auth.requires_login(). Please tell us more about the OS, the
> Python version.
>
> Massimo
>
> On Sep 30, 2:55 pm, Dmitri Zagidulin <[email protected]> wrote:
>
> > Then how do I account for the fact that (while being logged in) if I
> > remove the requires_login() decorator, I can access the vars inside
> > the function,
> > but if I put back the decorator, I cannot see the vars? And, similarly
> > - if I don't have requires_login, args get loaded into the args
> > dictionary, but if I do have the requires_login, I get a 404 NOT
> > FOUND?
>
> > If you don't believe me, can you at least point me in the right
> > direction (as far as explaining the workflow) -- since I'm not seeing
> > the vars in the logging statement in Augh > requires_login() >
> > decorator() -- where does requires_login get called from? Maybe I can
> > track down where the vars are being lost.
>
> > Any suggestions appreciated.
>
> > On Sep 30, 3:46 pm, mdipierro <[email protected]> wrote:
>
> > > I am sure that is not the case. If you submit vars to a function that
> > > requires login and you are not login you are redirected to login (in
> > > this case vars are lost, args are not), but if you are logged in the
> > > function works normally and the vars are in request.vars.
>
> > > On Sep 30, 2:28 pm, Dmitri Zagidulin <[email protected]> wrote:
>
> > > > It looks like functions that are decorated with auth.requires_login()
> > > > are not receiving their request.vars dictionary from the url.
>
> > > > For example, say I have an auth-protected function in a controller:
>
> > > > @auth.requires_login()
> > > > def index():
> > > >     """
> > > >     Login-protected index page
> > > >     """
> > > >     response.flash = str(request.vars)
> > > >     ...
>
> > > > And then link to it from another page:
> > > > {{=A('My Index', _href=URL(r=request, f='index', vars={'testvar':
> > > > 999}))}}
>
> > > > Assuming that I'm previous logged in, the flash results in an empty
> > > > dictionary -- no vars are actually passed in.
> > > > (Now, if I remove the requires_login() decorator, I can see the
> > > > 'testvar' variable just fine).
>
> > > > Looking in gluon/tools.py > Auth > requires_login(), on line 1418, I
> > > > noticed that while request.args are being encoded and passed onto the
> > > > login url, request.vars are not.
>
> > > > But when I added that in, so that the decorator now encoded and
> > > > passed
> > > > on the vars, restarted the server, etc, the flash was still coming up
> > > > empty -- the vars were not being passed on.
>
> > > > I put in a logging statement into the decorator (right around line
> > > > 1416), to see if self.environment.request.vars are at least set
> > > > correctly in the body of the function.
> > > > And they are not -- the 'testvar' variable is not making it into the
> > > > decorator at all.
>
> > > > Is this a bug or a feature? And if feature, how do I pass vars into
> > > > an
> > > > auth-protected function?
>
> > > > Also, passed-in args are not being handled correctly either.
> > > > For instance, for the index() function above, if I link to it like so:
> > > > {{=A('My Index', _href=URL(r=request, f='index', args='testarg'))}}
>
> > > > and display the contents of display.args (as a response.flash, etc),
> > > > and
> > > > do NOT auth-protect it, the testarg shows up.
> > > > But if I decorate it with requires_login, and click on that same link,
> > > > I
> > > > get a
> > > > 404 NOT FOUND
>
> > > > So, it seems like instead of loading 'testarg' into the contents of
> > > > args, it tries to parse it as part of post-login routing.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to