I am currently using auth.login() and auth.register() forms on the same page
I would like to use the following code for the login (to allow users to
sign up with either username or email)
auth.settings.login_userfield = 'email'
if request.vars.email and IS_EMAIL()(request.vars.email)[1]:
auth.settings.login_userfield = 'username'
request.vars.username = request.vars.email
request.post_vars.username = request.vars.username
request.vars.email = None
request.post_vars.email = None
return dict(form=auth.login())
So the whole function looks like this (including the registration form):
def mypage():
auth.settings.login_userfield = 'email'
#to allow user to login with either username or email
if request.vars.email and IS_EMAIL()(request.vars.email)[1]:
auth.settings.login_userfield = 'username'
request.vars.username = request.vars.email
request.post_vars.username = request.vars.username
request.vars.email = None
request.post_vars.email = None
return dict(login_form=auth.login(), register_form=auth.register())
Because the auth.login() and auth.register() forms both have inputs with
the same name (password, email, username), how can I differentiate between
whether a form was submitted by the login or the register form (both have
request.vars.email). I only want the above logic to affect the auth.login()
form, and may also want certain logic to only affect the register form.
I was considering a check for request.vars.username (which is not present
in the login form), but if the registration form username input is empty,
then request.vars.username is still None (thus can't differentiate b/t
login and register).
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.