I have just started to look at web2py and wish to use username rather than email to log in.
I have added the following :-
auth.define_tables(username=True, signature=False)
and I need to add the validator, but I don’t know where to put it (sounds silly I know).
I have tried a few options and looked at many examples – but they all create a new table rather than use the existing auth_user.
I tried :-
auth_table = auth.settings.table_user
auth_table.username.requires = IS_NOT_IN_DB(db, auth_table.username)
auth.define_tables(username=True, signature=False)
But auth_table is None.
auth.settings.table_userwill not exist until after you callauth.define_tables(). So, just change the order of your code:Note, if you define your
dbobject withDAL(..., lazy_tables=True), auth.settings.table_user will not exist. In that case, you can instead doauth_table = auth.table_user().