1

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.

1 Answer 1

3

auth.settings.table_user will not exist until after you call auth.define_tables(). So, just change the order of your code:

auth.define_tables(username=True, signature=False) auth_table = auth.settings.table_user auth_table.username.requires = IS_NOT_IN_DB(db, auth_table.username) 

Note, if you define your db object with DAL(..., lazy_tables=True), auth.settings.table_user will not exist. In that case, you can instead do auth_table = auth.table_user().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.