I thought auth.register() should also check self.settings.login_userfield to
decide which field to select the user to login after the form is accepted.
The modification fixes the problem of using ExtendedLoginFrom with default
auth
to register user by email. If you think it is proper and add it, that'd be
great.
BTW, I missed one line for the modification:
table_user = self.table_user()
+ if self.settings.login_userfield:
+ username = self.settings.login_userfield
+ elif 'username' in table_user.fields:
- if 'username' in table_user.fields:
username = 'username'
else:
username = 'email'
...
user = self.db(
table_user[username] == form.vars[username]
).select().first()
self.login_user(user)
Thank you
Massimo Di Pierro於 2013年5月7日星期二UTC+8上午1時51分27秒寫道:
>
> I am not sure the extended-login-form is designed to work with nonstandard
> username fields but, If this works for you, we can add the lines.
>
> On Monday, 6 May 2013 10:13:21 UTC-5, Ting-Yu Chou wrote:
>>
>> Hello,
>>
>> I use ExtendedLoginForm to include both default auth and
>> FaceBookAccount, and still want to use 'email' for default
>> registration, I have following in my models/db.py:
>>
>> auth.define_tables(username=True)
>> db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username
>> )
>> db.auth_user.username.writable = db.auth_user.username.readable = False
>> db.auth_user.first_name.writable = db.auth_user.first_name.readable =
>> False
>> db.auth_user.last_name.writable = db.auth_user.last_name.readable =
>> False
>> auth.settings.login_userfield = 'email'
>>
>>
>> But it fails when I trying to register. I think it's because
>> auth.register() uses field 'username' to select the user if the
>> table_user does have the field:
>>
>> table_user = self.table_user()
>> if 'username' in table_user.fields:
>> username = 'username'
>> else:
>> username = 'email'
>> ...
>> user = self.db(
>> table_user[username] == form.vars[username]
>> ).select().first()
>> self.login_user(user)
>>
>>
>> I'm not sure, but maybe it should be modified like below?
>>
>> 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'
>> ...
>> user = self.db(
>> table_user[username] == form.vars[username]
>> ).select().first()
>> self.login_user(user)
>>
>>
>> Thanks
>>
>>
--
---
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/groups/opt_out.