[web2py] Re: username and email login (auth)

2014-02-24 Thread Ruud Schroen
http://www.web2pyslices.com/slice/show/1642/login-with-username-and-email

On Friday, December 9, 2011 1:22:57 PM UTC+1, Francisco Costa wrote:

 lots of users on login form submit their email instead of the
 username..

 it seems that auth.define_tables(username=True) forces username login
 but it is possible to have both?


-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: username and email login (auth)

2014-02-24 Thread Richard Vézina
Not sure this approach work with ldap_auth.py contrib...

Richard


On Mon, Feb 24, 2014 at 8:37 AM, Ruud Schroen r...@formatics.nl wrote:

 http://www.web2pyslices.com/slice/show/1642/login-with-username-and-email


 On Friday, December 9, 2011 1:22:57 PM UTC+1, Francisco Costa wrote:

 lots of users on login form submit their email instead of the
 username..

 it seems that auth.define_tables(username=True) forces username login
 but it is possible to have both?

  --
 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+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: username and email login (auth)

2014-02-19 Thread Michelle Bergeron
I tried using this code to let a user login with either username or email. 
Previously it was only allowing email. It's still trying to validate the 
entry as an email address though, and if I enter a username it gives me an 
error Invalid Email. How can I eliminate or circumvent that email 
validation?

On Saturday, June 1, 2013 7:27:05 PM UTC-7, Gustavo Souza wrote:

 Worked for me the following code:

 if 'login' in request.args:
 auth.settings.login_userfield = 'username'
 if request.vars.username and not 
 IS_EMAIL()(request.vars.username)[1]:
 auth.settings.login_userfield = 'email'
 request.vars.email = request.vars.username
 request.post_vars.email = request.vars.email
 request.vars.username = None
 request.post_vars.username = None

 return dict(form=auth.login())

 Em sexta-feira, 9 de dezembro de 2011 10h22min57s UTC-2, Francisco Costa 
 escreveu:

 lots of users on login form submit their email instead of the
 username..

 it seems that auth.define_tables(username=True) forces username login
 but it is possible to have both?



-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: username and email login (auth)

2013-08-06 Thread Richard Vézina
Create a IS_NOT_EMAIL() validator :

class IS_NOT_EMAIL:
def __init__(self, error_message='You can\'t use email as username'):
self.e = error_message
def __call__(self, value):
if not IS_EMAIL()(value)[1]:
return (value, self.e)
return (value, None)

Base on this!!


I wonder why we don't set flag on validators for reverse validation when
apply, for instance : IS_EMAIL(..., *complement=True*) will return an error
if input is email... This is use in python petl project :
http://petl.readthedocs.org/en/latest/

Thanks.

Richard


On Sun, Jun 2, 2013 at 9:20 AM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 Do you need the commented lines?

 #request.vars.email = request.vars.username
 request.post_vars.email = request.vars.email
 #request.vars.username = None
 request.post_vars.username = None

 On Saturday, 1 June 2013 21:27:05 UTC-5, Gustavo Souza wrote:

 Worked for me the following code:

 if 'login' in request.args:
 auth.settings.login_userfield = 'username'
 if request.vars.username and not IS_EMAIL()(request.vars.**
 username)[1]:
 auth.settings.login_userfield = 'email'
 request.vars.email = request.vars.username
 request.post_vars.email = request.vars.email
 request.vars.username = None
 request.post_vars.username = None

 return dict(form=auth.login())

 Em sexta-feira, 9 de dezembro de 2011 10h22min57s UTC-2, Francisco Costa
 escreveu:

 lots of users on login form submit their email instead of the
 username..

 it seems that auth.define_tables(username=**True) forces username login
 but it is possible to have both?

  --

 ---
 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+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 

--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: username and email login (auth)

2013-06-02 Thread Gustavo Souza
Worked for me the following code:

if 'login' in request.args:
auth.settings.login_userfield = 'username'
if request.vars.username and not 
IS_EMAIL()(request.vars.username)[1]:
auth.settings.login_userfield = 'email'
request.vars.email = request.vars.username
request.post_vars.email = request.vars.email
request.vars.username = None
request.post_vars.username = None

return dict(form=auth.login())

Em sexta-feira, 9 de dezembro de 2011 10h22min57s UTC-2, Francisco Costa 
escreveu:

 lots of users on login form submit their email instead of the
 username..

 it seems that auth.define_tables(username=True) forces username login
 but it is possible to have both?


-- 

--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: username and email login (auth)

2013-06-02 Thread Massimo Di Pierro
Do you need the commented lines?

#request.vars.email = request.vars.username
request.post_vars.email = request.vars.email
#request.vars.username = None
request.post_vars.username = None

On Saturday, 1 June 2013 21:27:05 UTC-5, Gustavo Souza wrote:

 Worked for me the following code:

 if 'login' in request.args:
 auth.settings.login_userfield = 'username'
 if request.vars.username and not 
 IS_EMAIL()(request.vars.username)[1]:
 auth.settings.login_userfield = 'email'
 request.vars.email = request.vars.username
 request.post_vars.email = request.vars.email
 request.vars.username = None
 request.post_vars.username = None

 return dict(form=auth.login())

 Em sexta-feira, 9 de dezembro de 2011 10h22min57s UTC-2, Francisco Costa 
 escreveu:

 lots of users on login form submit their email instead of the
 username..

 it seems that auth.define_tables(username=True) forces username login
 but it is possible to have both?



-- 

--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: username and email login (auth)

2011-12-11 Thread Francisco Costa
has anyone successfully tried this?


On Dec 9, 6:01 pm, Francisco Costa m...@franciscocosta.com wrote:
 No error,
 it enters in the if loop, but it seems that the
 auth.settings.login_userfield = 'email' doesn't change anything

 On Dec 9, 5:34 pm, Anthony abasta...@gmail.com wrote:



  The idea is to create the form with the 'username' field by default, but
  when submitted, if the 'username' field contains an email address, change
  the setting and also copy the email address to request.vars.email before
  calling the login() method again. The second call to login will proceed as
  if the email address is being used for login. If it's not working, I'm not
  sure where it's breaking down. Did you get an error, or it just didn't
  check the email address properly?

  Anthony

  On Friday, December 9, 2011 12:17:18 PM UTC-5, Francisco Costa wrote:

   it seems it dosen't work.. maybe because I have a username field
   defined in my auth_user?

   On Dec 9, 4:46 pm, Anthony abas...@gmail.com wrote:
Not tested, but maybe something like:

def user():
    custom_auth.settings.login_userfield = 'username'
    if request.args(0) == 'login':
        if request.vars.username and not
IS_EMAIL()(request.vars.username)[1]:
            custom_auth.settings.login_userfield = 'email'
            request.vars.email = request.vars.username
        return dict(form=custom_auth.login())
    return dict(form=custom_auth())

On Friday, December 9, 2011 10:52:56 AM UTC-5, Francisco Costa wrote:

 I would prefer that way.. I what controller function? I'm using in
 form from default/user but I'm using a customauth

 On Dec 9, 3:02 pm, Anthony aba...@gmail.com wrote:
  Rather than write a whole new method, one trick might be in the 
  login
  controller function, check the incoming request.vars.username to see
   if
 it
  is an email address (using the IS_EMAIL validator). Then, depending
   on
  that, dynamically set auth.settings.login_userfield to either
   'email' or
  'username', and then call auth.login() as usual.

  Anthony

  On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco Costa wrote:

   yes, i think I'm going to build a custom method for login with
   username or email

   On Dec 9, 2:13 pm, Anthony aba...@gmail.com wrote:
Are you saying you want users to be able to login with either
   their
username or their email address? For that, I think you might
   need a
   custom
login method. On the other hand, if you simply want to allow
   users to
   have
a username, but always login with email address, you should be
   able
 to
   do:

auth.settings.login_userfield = 'email'

Anthony

On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa
   wrote:

 lots of users on login form submit their email instead of the
 username..

 it seems that auth.define_tables(username=True) forces 
 username
 login
 but it is possible to have both?


[web2py] Re: username and email login (auth)

2011-12-11 Thread Francisco Costa
Gotta after some debugging: post_vars was missing

So this will verification will work for username or email login:

if request.vars.username and not IS_EMAIL()
(request.vars.username)[1]:
auth.settings.login_userfield = 'email'
request.vars.email = request.vars.username
request.post_vars.email = request.vars.email
request.vars.username = None
request.post_vars.username = None



On Dec 11, 1:30 pm, Francisco Costa m...@franciscocosta.com wrote:
 has anyone successfully tried this?

 On Dec 9, 6:01 pm, Francisco Costa m...@franciscocosta.com wrote:







  No error,
  it enters in the if loop, but it seems that the
  auth.settings.login_userfield = 'email' doesn't change anything

  On Dec 9, 5:34 pm, Anthony abasta...@gmail.com wrote:

   The idea is to create the form with the 'username' field by default, but
   when submitted, if the 'username' field contains an email address, change
   the setting and also copy the email address to request.vars.email before
   calling the login() method again. The second call to login will proceed as
   if the email address is being used for login. If it's not working, I'm not
   sure where it's breaking down. Did you get an error, or it just didn't
   check the email address properly?

   Anthony

   On Friday, December 9, 2011 12:17:18 PM UTC-5, Francisco Costa wrote:

it seems it dosen't work.. maybe because I have a username field
defined in my auth_user?

On Dec 9, 4:46 pm, Anthony abas...@gmail.com wrote:
 Not tested, but maybe something like:

 def user():
     custom_auth.settings.login_userfield = 'username'
     if request.args(0) == 'login':
         if request.vars.username and not
 IS_EMAIL()(request.vars.username)[1]:
             custom_auth.settings.login_userfield = 'email'
             request.vars.email = request.vars.username
         return dict(form=custom_auth.login())
     return dict(form=custom_auth())

 On Friday, December 9, 2011 10:52:56 AM UTC-5, Francisco Costa wrote:

  I would prefer that way.. I what controller function? I'm using in
  form from default/user but I'm using a customauth

  On Dec 9, 3:02 pm, Anthony aba...@gmail.com wrote:
   Rather than write a whole new method, one trick might be in the 
   login
   controller function, check the incoming request.vars.username to 
   see
if
  it
   is an email address (using the IS_EMAIL validator). Then, 
   depending
on
   that, dynamically set auth.settings.login_userfield to either
'email' or
   'username', and then call auth.login() as usual.

   Anthony

   On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco Costa 
   wrote:

yes, i think I'm going to build a custom method for login with
username or email

On Dec 9, 2:13 pm, Anthony aba...@gmail.com wrote:
 Are you saying you want users to be able to login with either
their
 username or their email address? For that, I think you might
need a
custom
 login method. On the other hand, if you simply want to allow
users to
have
 a username, but always login with email address, you should be
able
  to
do:

 auth.settings.login_userfield = 'email'

 Anthony

 On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa
wrote:

  lots of users on login form submit their email instead of 
  the
  username..

  it seems that auth.define_tables(username=True) forces 
  username
  login
  but it is possible to have both?


[web2py] Re: username and email login (auth)

2011-12-11 Thread Anthony
Sorry, good catch.

On Sunday, December 11, 2011 11:30:12 AM UTC-5, Francisco Costa wrote:

 Gotta after some debugging: post_vars was missing

 So this will verification will work for username or email login:

 if request.vars.username and not IS_EMAIL()
 (request.vars.username)[1]:
 auth.settings.login_userfield = 'email'
 request.vars.email = request.vars.username
 request.post_vars.email = request.vars.email
 request.vars.username = None
 request.post_vars.username = None

 On Dec 11, 1:30 pm, Francisco Costa m@franciscocosta.com wrote:
  has anyone successfully tried this?
 
  On Dec 9, 6:01 pm, Francisco Costa m@franciscocosta.com wrote:
 
 
 
 
 
 
 
   No error,
   it enters in the if loop, but it seems that the
   auth.settings.login_userfield = 'email' doesn't change anything
 
   On Dec 9, 5:34 pm, Anthony abas...@gmail.com wrote:
 
The idea is to create the form with the 'username' field by default, 
 but
when submitted, if the 'username' field contains an email address, 
 change
the setting and also copy the email address to request.vars.email 
 before
calling the login() method again. The second call to login will 
 proceed as
if the email address is being used for login. If it's not working, 
 I'm not
sure where it's breaking down. Did you get an error, or it just 
 didn't
check the email address properly?
 
Anthony
 
On Friday, December 9, 2011 12:17:18 PM UTC-5, Francisco Costa wrote:
 
 it seems it dosen't work.. maybe because I have a username field
 defined in my auth_user?
 
 On Dec 9, 4:46 pm, Anthony aba...@gmail.com wrote:
  Not tested, but maybe something like:
 
  def user():
  custom_auth.settings.login_userfield = 'username'
  if request.args(0) == 'login':
  if request.vars.username and not
  IS_EMAIL()(request.vars.username)[1]:
  custom_auth.settings.login_userfield = 'email'
  request.vars.email = request.vars.username
  return dict(form=custom_auth.login())
  return dict(form=custom_auth())
 
  On Friday, December 9, 2011 10:52:56 AM UTC-5, Francisco Costa 
 wrote:
 
   I would prefer that way.. I what controller function? I'm 
 using in
   form from default/user but I'm using a customauth
 
   On Dec 9, 3:02 pm, Anthony aba...@gmail.com wrote:
Rather than write a whole new method, one trick might be in 
 the login
controller function, check the incoming 
 request.vars.username to see
 if
   it
is an email address (using the IS_EMAIL validator). Then, 
 depending
 on
that, dynamically set auth.settings.login_userfield to either
 'email' or
'username', and then call auth.login() as usual.
 
Anthony
 
On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco 
 Costa wrote:
 
 yes, i think I'm going to build a custom method for login 
 with
 username or email
 
 On Dec 9, 2:13 pm, Anthony aba...@gmail.com wrote:
  Are you saying you want users to be able to login with 
 either
 their
  username or their email address? For that, I think you 
 might
 need a
 custom
  login method. On the other hand, if you simply want to 
 allow
 users to
 have
  a username, but always login with email address, you 
 should be
 able
   to
 do:
 
  auth.settings.login_userfield = 'email'
 
  Anthony
 
  On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco 
 Costa
 wrote:
 
   lots of users on login form submit their email instead 
 of the
   username..
 
   it seems that auth.define_tables(username=True) forces 
 username
   login
   but it is possible to have both?



[web2py] Re: username and email login (auth)

2011-12-09 Thread Anthony
Are you saying you want users to be able to login with either their 
username or their email address? For that, I think you might need a custom 
login method. On the other hand, if you simply want to allow users to have 
a username, but always login with email address, you should be able to do:

auth.settings.login_userfield = 'email'

Anthony

On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa wrote:

 lots of users on login form submit their email instead of the
 username..

 it seems that auth.define_tables(username=True) forces username login
 but it is possible to have both?



[web2py] Re: username and email login (auth)

2011-12-09 Thread Francisco Costa
yes, i think I'm going to build a custom method for login with
username or email

On Dec 9, 2:13 pm, Anthony abasta...@gmail.com wrote:
 Are you saying you want users to be able to login with either their
 username or their email address? For that, I think you might need a custom
 login method. On the other hand, if you simply want to allow users to have
 a username, but always login with email address, you should be able to do:

 auth.settings.login_userfield = 'email'

 Anthony







 On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa wrote:

  lots of users on login form submit their email instead of the
  username..

  it seems that auth.define_tables(username=True) forces username login
  but it is possible to have both?


[web2py] Re: username and email login (auth)

2011-12-09 Thread Anthony
Rather than write a whole new method, one trick might be in the login 
controller function, check the incoming request.vars.username to see if it 
is an email address (using the IS_EMAIL validator). Then, depending on 
that, dynamically set auth.settings.login_userfield to either 'email' or 
'username', and then call auth.login() as usual.

Anthony

On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco Costa wrote:

 yes, i think I'm going to build a custom method for login with
 username or email

 On Dec 9, 2:13 pm, Anthony abas...@gmail.com wrote:
  Are you saying you want users to be able to login with either their
  username or their email address? For that, I think you might need a 
 custom
  login method. On the other hand, if you simply want to allow users to 
 have
  a username, but always login with email address, you should be able to 
 do:
 
  auth.settings.login_userfield = 'email'
 
  Anthony
 
 
 
 
 
 
 
  On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa wrote:
 
   lots of users on login form submit their email instead of the
   username..
 
   it seems that auth.define_tables(username=True) forces username login
   but it is possible to have both?



[web2py] Re: username and email login (auth)

2011-12-09 Thread Francisco Costa
I would prefer that way.. I what controller function? I'm using in
form from default/user but I'm using a customauth

On Dec 9, 3:02 pm, Anthony abasta...@gmail.com wrote:
 Rather than write a whole new method, one trick might be in the login
 controller function, check the incoming request.vars.username to see if it
 is an email address (using the IS_EMAIL validator). Then, depending on
 that, dynamically set auth.settings.login_userfield to either 'email' or
 'username', and then call auth.login() as usual.

 Anthony







 On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco Costa wrote:

  yes, i think I'm going to build a custom method for login with
  username or email

  On Dec 9, 2:13 pm, Anthony abas...@gmail.com wrote:
   Are you saying you want users to be able to login with either their
   username or their email address? For that, I think you might need a
  custom
   login method. On the other hand, if you simply want to allow users to
  have
   a username, but always login with email address, you should be able to
  do:

   auth.settings.login_userfield = 'email'

   Anthony

   On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa wrote:

lots of users on login form submit their email instead of the
username..

it seems that auth.define_tables(username=True) forces username login
but it is possible to have both?


[web2py] Re: username and email login (auth)

2011-12-09 Thread Anthony
Not tested, but maybe something like:

def user():
custom_auth.settings.login_userfield = 'username'
if request.args(0) == 'login':
if request.vars.username and not 
IS_EMAIL()(request.vars.username)[1]:
custom_auth.settings.login_userfield = 'email'
request.vars.email = request.vars.username
return dict(form=custom_auth.login())
return dict(form=custom_auth())


On Friday, December 9, 2011 10:52:56 AM UTC-5, Francisco Costa wrote:

 I would prefer that way.. I what controller function? I'm using in
 form from default/user but I'm using a customauth

 On Dec 9, 3:02 pm, Anthony abas...@gmail.com wrote:
  Rather than write a whole new method, one trick might be in the login
  controller function, check the incoming request.vars.username to see if 
 it
  is an email address (using the IS_EMAIL validator). Then, depending on
  that, dynamically set auth.settings.login_userfield to either 'email' or
  'username', and then call auth.login() as usual.
 
  Anthony
 
 
 
 
 
 
 
  On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco Costa wrote:
 
   yes, i think I'm going to build a custom method for login with
   username or email
 
   On Dec 9, 2:13 pm, Anthony aba...@gmail.com wrote:
Are you saying you want users to be able to login with either their
username or their email address? For that, I think you might need a
   custom
login method. On the other hand, if you simply want to allow users to
   have
a username, but always login with email address, you should be able 
 to
   do:
 
auth.settings.login_userfield = 'email'
 
Anthony
 
On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa wrote:
 
 lots of users on login form submit their email instead of the
 username..
 
 it seems that auth.define_tables(username=True) forces username 
 login
 but it is possible to have both?



[web2py] Re: username and email login (auth)

2011-12-09 Thread Francisco Costa
it seems it dosen't work.. maybe because I have a username field
defined in my auth_user?

On Dec 9, 4:46 pm, Anthony abasta...@gmail.com wrote:
 Not tested, but maybe something like:

 def user():
     custom_auth.settings.login_userfield = 'username'
     if request.args(0) == 'login':
         if request.vars.username and not
 IS_EMAIL()(request.vars.username)[1]:
             custom_auth.settings.login_userfield = 'email'
             request.vars.email = request.vars.username
         return dict(form=custom_auth.login())
     return dict(form=custom_auth())







 On Friday, December 9, 2011 10:52:56 AM UTC-5, Francisco Costa wrote:

  I would prefer that way.. I what controller function? I'm using in
  form from default/user but I'm using a customauth

  On Dec 9, 3:02 pm, Anthony abas...@gmail.com wrote:
   Rather than write a whole new method, one trick might be in the login
   controller function, check the incoming request.vars.username to see if
  it
   is an email address (using the IS_EMAIL validator). Then, depending on
   that, dynamically set auth.settings.login_userfield to either 'email' or
   'username', and then call auth.login() as usual.

   Anthony

   On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco Costa wrote:

yes, i think I'm going to build a custom method for login with
username or email

On Dec 9, 2:13 pm, Anthony aba...@gmail.com wrote:
 Are you saying you want users to be able to login with either their
 username or their email address? For that, I think you might need a
custom
 login method. On the other hand, if you simply want to allow users to
have
 a username, but always login with email address, you should be able
  to
do:

 auth.settings.login_userfield = 'email'

 Anthony

 On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa wrote:

  lots of users on login form submit their email instead of the
  username..

  it seems that auth.define_tables(username=True) forces username
  login
  but it is possible to have both?


[web2py] Re: username and email login (auth)

2011-12-09 Thread Anthony
The idea is to create the form with the 'username' field by default, but 
when submitted, if the 'username' field contains an email address, change 
the setting and also copy the email address to request.vars.email before 
calling the login() method again. The second call to login will proceed as 
if the email address is being used for login. If it's not working, I'm not 
sure where it's breaking down. Did you get an error, or it just didn't 
check the email address properly?

Anthony

On Friday, December 9, 2011 12:17:18 PM UTC-5, Francisco Costa wrote:

 it seems it dosen't work.. maybe because I have a username field
 defined in my auth_user?

 On Dec 9, 4:46 pm, Anthony abas...@gmail.com wrote:
  Not tested, but maybe something like:
 
  def user():
  custom_auth.settings.login_userfield = 'username'
  if request.args(0) == 'login':
  if request.vars.username and not
  IS_EMAIL()(request.vars.username)[1]:
  custom_auth.settings.login_userfield = 'email'
  request.vars.email = request.vars.username
  return dict(form=custom_auth.login())
  return dict(form=custom_auth())
 
 
 
 
 
 
 
  On Friday, December 9, 2011 10:52:56 AM UTC-5, Francisco Costa wrote:
 
   I would prefer that way.. I what controller function? I'm using in
   form from default/user but I'm using a customauth
 
   On Dec 9, 3:02 pm, Anthony aba...@gmail.com wrote:
Rather than write a whole new method, one trick might be in the login
controller function, check the incoming request.vars.username to see 
 if
   it
is an email address (using the IS_EMAIL validator). Then, depending 
 on
that, dynamically set auth.settings.login_userfield to either 
 'email' or
'username', and then call auth.login() as usual.
 
Anthony
 
On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco Costa wrote:
 
 yes, i think I'm going to build a custom method for login with
 username or email
 
 On Dec 9, 2:13 pm, Anthony aba...@gmail.com wrote:
  Are you saying you want users to be able to login with either 
 their
  username or their email address? For that, I think you might 
 need a
 custom
  login method. On the other hand, if you simply want to allow 
 users to
 have
  a username, but always login with email address, you should be 
 able
   to
 do:
 
  auth.settings.login_userfield = 'email'
 
  Anthony
 
  On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa 
 wrote:
 
   lots of users on login form submit their email instead of the
   username..
 
   it seems that auth.define_tables(username=True) forces username
   login
   but it is possible to have both?



[web2py] Re: username and email login (auth)

2011-12-09 Thread Francisco Costa
No error,
it enters in the if loop, but it seems that the
auth.settings.login_userfield = 'email' doesn't change anything

On Dec 9, 5:34 pm, Anthony abasta...@gmail.com wrote:
 The idea is to create the form with the 'username' field by default, but
 when submitted, if the 'username' field contains an email address, change
 the setting and also copy the email address to request.vars.email before
 calling the login() method again. The second call to login will proceed as
 if the email address is being used for login. If it's not working, I'm not
 sure where it's breaking down. Did you get an error, or it just didn't
 check the email address properly?

 Anthony







 On Friday, December 9, 2011 12:17:18 PM UTC-5, Francisco Costa wrote:

  it seems it dosen't work.. maybe because I have a username field
  defined in my auth_user?

  On Dec 9, 4:46 pm, Anthony abas...@gmail.com wrote:
   Not tested, but maybe something like:

   def user():
       custom_auth.settings.login_userfield = 'username'
       if request.args(0) == 'login':
           if request.vars.username and not
   IS_EMAIL()(request.vars.username)[1]:
               custom_auth.settings.login_userfield = 'email'
               request.vars.email = request.vars.username
           return dict(form=custom_auth.login())
       return dict(form=custom_auth())

   On Friday, December 9, 2011 10:52:56 AM UTC-5, Francisco Costa wrote:

I would prefer that way.. I what controller function? I'm using in
form from default/user but I'm using a customauth

On Dec 9, 3:02 pm, Anthony aba...@gmail.com wrote:
 Rather than write a whole new method, one trick might be in the login
 controller function, check the incoming request.vars.username to see
  if
it
 is an email address (using the IS_EMAIL validator). Then, depending
  on
 that, dynamically set auth.settings.login_userfield to either
  'email' or
 'username', and then call auth.login() as usual.

 Anthony

 On Friday, December 9, 2011 9:50:02 AM UTC-5, Francisco Costa wrote:

  yes, i think I'm going to build a custom method for login with
  username or email

  On Dec 9, 2:13 pm, Anthony aba...@gmail.com wrote:
   Are you saying you want users to be able to login with either
  their
   username or their email address? For that, I think you might
  need a
  custom
   login method. On the other hand, if you simply want to allow
  users to
  have
   a username, but always login with email address, you should be
  able
to
  do:

   auth.settings.login_userfield = 'email'

   Anthony

   On Friday, December 9, 2011 7:22:57 AM UTC-5, Francisco Costa
  wrote:

lots of users on login form submit their email instead of the
username..

it seems that auth.define_tables(username=True) forces username
login
but it is possible to have both?