register_fields, profile_fields

55 views
Skip to first unread message

Lucas

unread,
Sep 9, 2025, 6:30:12 AMSep 9
to py4web
hello one and all,

sorry if I'm hounding.  is there a quick way to do this in py4web like under web2py it was:

auth.settings.register_fields = ['prefix_title', 'first_name', 'last_name', 'zip', 'email', 'password']
auth.settings.profile_fields = ['prefix_title', 'first_name', 'last_name', 'zip', 'email']

under the db.py???

or do we have to go all auth.form.find('input#auth_first_name') .. ... etc., and mangle the form directly???  and if this is the only option, where exactly would we access that form because under auth.html it is only [[=form]]?

thank you in advance.  lucas

laundmo

unread,
Sep 11, 2025, 12:41:25 PMSep 11
to py4web
Hi Lucas,

the Auth fixture has a parameter extra_fields and extra_form_fields, is that what you're looking for?

Lucas

unread,
Sep 12, 2025, 12:55:38 AMSep 12
to py4web
I don't think so, I already used auth.extra_auth_user_fields to add extra fields to the auth_user table.  I'm simply trying to reorder those new extra fields to integrate them with the other automatic fields, like, first and last name fields.

Lucas

unread,
Sep 13, 2025, 6:51:45 AMSep 13
to py4web
ok, hey,  this is my recreation of the auth_user define table so that the register form will show the fields in the correct order:

db.define_table('auth_user',
    #Field('username', length=128, default='', unique=True),
    Field('email', length=128, default='', unique=True, comment="used for login. all lowercase.",),
    Field('prefix_title', length=4, requires=IS_IN_SET(('Mr.','Ms.','Mrs.','Dr.')), label="Prefix", comment='Enter your Name Prefix.',),
    Field('first_name', length=128, default='',),
    Field('last_name', length=128, default='',),
    Field('gender', length=6, default='FEMALE', requires=IS_IN_SET(('FEMALE','MALE',)), comment='Enter your Gender.',),
    Field('zip', length=12, requires=IS_NOT_EMPTY(), label="Zip Code", comment='Your Zip or Postal Code.',),
    #Field('birthdate', 'date', requires=NE, comment='Enter in Format: "YYYY-MM-DD"',),
    Field('password', length=256, default='',),
    Field('input_date', 'date', requires=IS_NOT_EMPTY(), default=date.today(), writable=False, readable=False, comment="format YYYY-MM-DD",),
    Field('sso_id', length=256, default='', writable=False, readable=False,), # For internal use by Auth
    Field('action_token', length=256, default='', writable=False, readable=False,), # For internal use by Auth
    Field('last_password_change', 'datetime', default=None, writable=False, readable=False,), # For internal use by Auth
    Field('past_passwords_hash', 'list:string', writable=False, readable=False,), # For internal use by Auth
    format = '%(email)s')

and the form looks good except the password does not have the retype_confirmation field.  how do I add that to the form?  really, how do I access the form to append that field?

Massimo DiPierro

unread,
Sep 13, 2025, 12:26:18 PMSep 13
to py4web
The password confirmation field does not belong in the DB. It is injected in the form itself when needed. That is not working for you because your "password" field is not correct It should be 

Field("password", "password", requires=[CRYPT()], readable=False, writable=False, label="Password")

where you import CRYPT from pydal.validators. This is very important to make sure that the password is always stored salted and hashed and there is no way to accidentally extract it from database.
if the second argument (type) is "password" Auth understands this is a password and will automatically add the confirmation field to Register forms.

Lucas

unread,
Sep 13, 2025, 6:06:08 PMSep 13
to py4web
yes, that worked perfectly.  thank you Massimo.  

and further, I had to place the db.define_table(...) directly under the "auth = Auth(...)" line  in the common.py file in order to work.  it does not work in the model.py file.  Lucas

Massimo DiPierro

unread,
Sep 13, 2025, 8:24:31 PMSep 13
to Lucas, py4web
I am thinking of making the requires CRYPT default for password fields

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/27aafabb-2ef8-4486-a22d-38cbd83ab276n%40googlegroups.com.
Message has been deleted

Massimo DiPierro

unread,
Sep 14, 2025, 7:30:01 PMSep 14
to py4web
Looks like this is already the case.
Reply all
Reply to author
Forward
0 new messages