What is the purpose of auth.settings.login_userfield?
38 views
Skip to first unread message
Ray (a.k.a. Iceberg)
unread,
Apr 6, 2014, 3:16:23 AM4/6/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Just want to double confirm.
1. I found many following lines in tools.py:
userfield = self.settings.login_userfield or 'username' \ if 'username' in table_user.fields else 'email'
it means:
if 'username' in table_user.fields: userfield = self.settings.login_userfield or 'username' else: userfield = 'email
2. If we used a slightly different source code like this:
userfield = self.settings.login_userfield or ('username' if 'username' in table_user.fields else 'email')
it means something quite different:
if self.settings.login_userfield: # if user explicitly define the login_userfield userfield = self.settings.login_userfield # then use it unconditionally else: # otherwise automatically determine one userfield = 'username' if 'username' in table_user.fields else 'email'
So, to double confirm, what is the design purpose of auth.settings.login_userfield? If it is #1, I recommend to use a pair of brackets to avoid misunderstanding.
userfield = (self.settings.login_userfield or 'username' ) if 'username' in table_user.fields else 'email'
Ray (a.k.a. Iceberg)
unread,
Apr 6, 2014, 3:02:41 PM4/6/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to web...@googlegroups.com
Well, now I believe the #2 purpose is the design intention, based on this section in Auth.register():
table_user = self.table_user() if self.settings.login_userfield: username = self.settings.login_userfield elif 'username' in table_user.fields: username = 'username' else: username = 'email'
In this case, I believe #1 is a bug and need to be fixed.
Anthony
unread,
Apr 6, 2014, 9:38:28 PM4/6/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to web...@googlegroups.com
Yes, seems like a bug. I guess no one uses this setting (probably because it's not documented).