auth, redirect after login

967 views
Skip to first unread message

roy...@gmx.de

unread,
Jun 27, 2013, 9:36:27 AM6/27/13
to web...@googlegroups.com


hello together,

my problem is , i want a simply redirect after a user is logged in.

i am using the auth setup from web2py:



my db.py:

auth = Auth(db)
auth.define_tables(username=True)
auth.settings.login_next = URL('welcome')   this has no effect, after  a user login the index page is still shown


the controller:

def index():this is my index page, the first page show to the user, where the user can login or register
   
    user_auth = auth.login()
    user_auth.add_button('register me', URL('register_user'))
  
   
    return dict(user_auth = user_auth)
      
def invalid_user():
    return dict()
      
def welcome():after login was succsesfull the user should be directed to welcome
    search = FORM('Search for:', INPUT(_name='name'), INPUT(_type='submit', _value = 'go!!!!'))
   
    return dict(search = search)
   
   
def register_user():
    register = auth.register()
   
    if register.process().accepted:
        redirect(URL('welcome'))
 
   
    return dict(register = register)


the view: this is the first site that the user is shown
<h1>Login:</h1>
<br>
{{=user_auth}}
it simply show the form from index() its auth.login()


the flow is that the user first see the index page with the login,
now user is able to login or create a account,
if the user log in , with an allready created account she schould be redircted to the welcome page.



kind regards

Bartek






LightOfMooN

unread,
Oct 11, 2013, 8:34:35 AM10/11/13
to web...@googlegroups.com
In v 2.7.2 don't work redirects after login and logout.
How to fix it?

четверг, 27 июня 2013 г., 19:36:27 UTC+6 пользователь roy...@gmx.de написал:

lesssugar

unread,
Oct 11, 2013, 1:05:31 PM10/11/13
to
Bartek, did you try using next in your login function?

user_auth = auth.login(next=URL('controller_name', 'function_name')

LightOfMooN

unread,
Oct 11, 2013, 1:00:11 PM10/11/13
to
Yes, I tried.
It works with login, but not with logout.

пятница, 11 октября 2013 г., 22:37:20 UTC+6 пользователь lesssugar написал:
Did you try using next in your login function?

user_auth = auth.login(next=URL('controller_name', 'function_name')


On Friday, October 11, 2013 2:34:35 PM UTC+2, LightOfMooN wrote:

lesssugar

unread,
Oct 11, 2013, 1:04:36 PM10/11/13
to web...@googlegroups.com
What do you mean it doesn't wok with logout? Linking your logout to /default/user/logout should log user out and simply redirect to default/index. Do you want to redirect user to other URL with /default/user/logout ?

On Friday, October 11, 2013 6:58:45 PM UTC+2, LightOfMooN wrote:
Yes, I tried.
It works with login, but not with logout.

пятница, 11 октября 2013 г., 22:37:20 UTC+6 пользователь lesssugar написал:
Did you try using next in your login function?

user_auth = auth.login(next=URL('controller_name', 'function_name')


On Friday, October 11, 2013 2:34:35 PM UTC+2, LightOfMooN wrote:

LightOfMooN

unread,
Oct 11, 2013, 1:15:03 PM10/11/13
to web...@googlegroups.com
def logout():
    auth_logout = auth.logout(next=URL('default', 'index'))
    return dict(auth_logout = auth_logout)

in template:
    {{=auth_logout}}

And it returns None and no redirects.

Other variation:
def user():
    return dict(form=auth())

in template:
    {{=form}}

If i go to url /default/user/login?_next=blablabla, I redirected to 'blablabla' after login.
If i go to url /default/user/logout?_next=blablabla, I stay at /default/user/logout after logout. Redirect doesn't work there.

пятница, 11 октября 2013 г., 23:04:36 UTC+6 пользователь lesssugar написал:

lesssugar

unread,
Oct 11, 2013, 1:18:19 PM10/11/13
to web...@googlegroups.com
How about a simple logout-link:

<a href="{{=URL('default', 'user', args='logout')}}">Logout</a>

This also does not redirect to default/index when clicked?

LightOfMooN

unread,
Oct 11, 2013, 3:10:12 PM10/11/13
to web...@googlegroups.com
I use just such link. But the problem is, that when user click on it, He logout and stays on /default/user/logout page. It's terrible.

пятница, 11 октября 2013 г., 23:18:19 UTC+6 пользователь lesssugar написал:

lesssugar

unread,
Oct 11, 2013, 3:30:31 PM10/11/13
to web...@googlegroups.com
If you use the newest version, it's most probably a bug. Give the guys time to fix it or move back to previous stable version.

LightOfMooN

unread,
Oct 11, 2013, 5:43:04 PM10/11/13
to web...@googlegroups.com
It's really strange.
I moved back to 2.4.6 and the problem still remain.
But in our other server with 2.4.6 web2py there are no that problem. I tested both servers on the same app.

суббота, 12 октября 2013 г., 1:30:31 UTC+6 пользователь lesssugar написал:

Massimo Di Pierro

unread,
Oct 11, 2013, 6:35:34 PM10/11/13
to web...@googlegroups.com
I cannot reproduce any of your problems. The redirection works fine for me in 2.7.2. Something else may be affecting your redirection. 

There are some error in your code, although, not cause of your problem:

def register_user():
    register = auth.register()
    if register.process().accepted:  #### WRONG
        redirect(URL('welcome'))

because you cannot process() and registration form. it is already processed Should be:

def register_user():
    register = auth.register(next=URL('welcome'))
    return dict(register = register)

You display the login form in the index page even if the user is already logged in.

The button to the register page will redirect to the profile page if the user is already logged in.

LightOfMooN

unread,
Oct 11, 2013, 6:49:24 PM10/11/13
to web...@googlegroups.com
I changed in gluon/tools.py line 2421:
    next = self.settings.logout_next
with:
    next = self.get_vars_next()

And now logout redirects users, if there is _next var in the url.
So, now all works fine, but I don't know, what other effects may occur this replacement.

пятница, 11 октября 2013 г., 23:15:03 UTC+6 пользователь LightOfMooN написал:
Message has been deleted

Massimo Di Pierro

unread,
Oct 11, 2013, 8:32:09 PM10/11/13
to web...@googlegroups.com
This helps. You are right there is a problem with logout next. That is now fixed in trunk based on your suggestion. The problem about login I cannot reproduce.

I deleted your other post. Never post your admin password. That would give full access to your server to everybody. Make sure you change the password immediately.

Massimo

LightOfMooN

unread,
Oct 12, 2013, 1:16:30 AM10/12/13
to web...@googlegroups.com
Thanks, but it was not necessary :)
It was the special server to show the problem.

The problem about login:
If there are no _next var, I think, it should redirect to auth.settings.login_next url, but it doesn't happen.

суббота, 12 октября 2013 г., 6:32:09 UTC+6 пользователь Massimo Di Pierro написал:

Junior Phanter

unread,
Oct 12, 2013, 8:33:58 AM10/12/13
to web...@googlegroups.com
Sorry to ask, but you went through a recent update of web2py, more precisely the version 2.6.x to version 2.7.x?
If you recently updated, you must copy the file web2py.js the admin folder and appadmin.html from welcome
application  to your application.




2013/10/12 LightOfMooN <vlads...@yandex.ru>

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages