login_next and next var

108 views
Skip to first unread message

Annet

unread,
Feb 3, 2014, 8:16:49 AM2/3/14
to web...@googlegroups.com
I have the following setting:

auth.settings.login_next = URL('cms', 'default', 'my_login')

'my_login' takes care of generating a menu and setting some
varaible depending on who logs in.

Normally the function redirects to /cms/default/index

In my application I have a few buttons that href functions for which
login is required:

<a class="btn btn-default" href="{{=URL('cms', 'group', 'connect', args=request.args())}}" role="button">


The connect function is decorated the following way:

@auth.requires(lambda: auth.has_membership(ROOT) or auth.has_membership(GROUP))
def connect():
    return dict(form=form)

The first problem is that the 'group' controller needs the menu to be generated, so the call to
'connect' fails.


I thought of replacing the button with:

<a class="btn btn-default" href="{{=URL('cms', 'default', 'user', args='login')}}" role="button">

and probably adding vars=dict(next='URL('cms', 'group', 'connect', args=request.args())')
But it's not the login function that needs the 'next' var but the 'my_login' function.

I wonder whether there is an easier way to get the behavior I want.


Kind regards,

Annet

Massimo Di Pierro

unread,
Feb 3, 2014, 9:36:21 AM2/3/14
to web...@googlegroups.com
I think the problem is that

 vars=dict(next='URL('cms', 'group', 'connect', args=request.args())')

should be

 vars=dict(_next='URL('cms', 'group', 'connect', args=request.args())')

Annet

unread,
Feb 4, 2014, 3:04:52 AM2/4/14
to web...@googlegroups.com
Massimo,

Thanks for your reply.

I tried:

<p class="text-center"><a class="btn btn-default" onclick="javascript:openwindow('{{=URL('cms', 'default', 'user', args=['login', request.args(0)], vars=dict(_next='URL('cms', 'group', 'connect', args=request.args())'))}}', 'connect')" role="button">Login</a>

But that gives me the following error:

Traceback (most recent call last):
File "/Users/annet/web2py/gluon/restricted.py", line 216, in restricted
ccode = compile2(code, layer)
File "/Users/annet/web2py/gluon/restricted.py", line 199, in compile2
return compile(code.rstrip().replace('\r\n', '\n') + '\n', layer, 'exec')
File "/Users/annet/web2py/applications/init/views/default/test.html", line 91
response.write(URL('cms', 'default', 'user', args=['login', request.args(0)], vars=dict(_next='URL('cms', 'group', 'connect', args=request.args())')))
^
SyntaxError: invalid syntax


Kind regards,

Annet

Massimo Di Pierro

unread,
Feb 4, 2014, 9:20:45 AM2/4/14
to web...@googlegroups.com
Notice extra ' before 'URL

Annet

unread,
Feb 4, 2014, 1:32:52 PM2/4/14
to web...@googlegroups.com

Notice extra ' before 'URL

When I remove the ' '  around the URL

 <a class="btn btn-default" onclick="javascript:openwindow('{{=URL('cms', 'default', 'user', args=['login', request.args(0)], vars=dict(_next=URL('cms', 'group', 'connect', args=request.args(0))))}}', 'connect')" role="button">Login</a>

The button is rendered the following way:

<a class="btn btn-default" role="button "onclick="javascript:openwindow('/cms/'default/user/login/4?_next=%2Fcms%2Fgroup%2Fconnect%2F4', 'connect')" >Login</a>

The first =URL converted to a url the second =URL is not.

Is what I want not possible?


Kind regards,

Annet

Jonathan Lundell

unread,
Feb 4, 2014, 1:49:50 PM2/4/14
to web2py
It's a URL; it's just %-escaped because it's in a query string (vars).

Annet

unread,
Feb 5, 2014, 7:56:59 AM2/5/14
to web...@googlegroups.com
Hi Jonathan,

Thanks for your reply.


It's a URL; it's just %-escaped because it's in a query string (vars).

 You're right, redirect(request.vars._next) does work.


Kind regards,

Annet

Trevor Strauss

unread,
Mar 13, 2014, 12:32:32 PM3/13/14
to web...@googlegroups.com
Hi Annet, I'm somewhat new...can you explain how you ended up getting this to work?  I am encountering same issue with login button I've created for jqm layout.  Thanks,Trevor

Trevor Strauss

unread,
Mar 13, 2014, 1:38:15 PM3/13/14
to web...@googlegroups.com
Hi Jonathan, I've been banging my head on this all day, how do I get _next  to work?

Annet

unread,
Mar 15, 2014, 4:02:10 AM3/15/14
to web...@googlegroups.com
Hi Trevor,

The following button works for me:

<p class="text-center"><a class="btn btn-default" onclick="javascript:openwindow('{{=URL('cms', 'default', 'user', args=['login', request.args(0)], vars=dict(nxt=URL('cms', 'group', 'connect', args=[request.args(0), request.args(1)])))}}', 'connect')" role="button">Login</a>


In cms/default/user

if request.args(0) == 'login':
        if request.vars.nxt:
            session.nxt = request.vars.nxt


In cms/default/my_login

if session.nxt:
        redirect(session.nxt)
    else:
        redirect(URL('index'))


I hope this is helpful.

Annet
Reply all
Reply to author
Forward
0 new messages