custom auth table

283 views
Skip to first unread message

patito feo

unread,
Oct 11, 2020, 10:57:47 PM10/11/20
to py4web
Hi all,

Havent see any documentation on this matter. Ive been trying to make it work based on web2py but dont know if posible in py4web and where it should be placed.


Thanx,

Massimo

unread,
Oct 12, 2020, 12:31:41 AM10/12/20
to py4web
If you look into common.py you find this...

auth = Auth(session, db, define_tables=False) # define the object
auth.enable(uses=(session, T, db), env=dict(T=T)) # exposes the action

You can do:

auth = Auth(session, db, define_tables=False) # define the object
db.define_table('auth_user', ....)
auth.enable(uses=(session, T, db), env=dict(T=T)) # exposes the action

and you can make your own auth_user table but make sure it contains the basic fields.
There is only one table auth_user.

You can also do:

auth = Auth(session, db, define_tables=True, extra_fields = [Field('birthday', 'datetime')])
auth.enable(uses=(session, T, db), env=dict(T=T)) # exposes the action

and just add fields to the table.

patito feo

unread,
Oct 12, 2020, 8:43:06 AM10/12/20
to py4web
Thank you Massimo, It worked perfectly.

Mamisoa Andriantafika

unread,
Feb 14, 2021, 6:17:12 PM2/14/21
to py4web
Hi,

Can you add an auth.signature in the auth_user table as this, done with Web2py ?

-----------------------------------------------------
auth.settings.extra_fields['auth_user']= [  Field('maiden_name_pid6','string', label='Maiden name'),
                                            Field('dob_pid7','date', label='Date of birth'), 
                                            auth.signature]

def represent_auth(auth_ref, row):
    user = db(db.auth_user.id == auth_ref).select(db.auth_user.first_name, db.auth_user.last_name).first()
    return ('%(first_name)s %(last_name)s' % user) if user else '<system>'  # else assume it was the scheduler.

auth.signature.created_by.represent = auth.signature.modified_by.represent = represent_auth


auth.define_tables(username=False, signature=False)

---------------------------------------------

Mamisoa

Jim Steil

unread,
Feb 15, 2021, 10:21:58 AM2/15/21
to py4web
I think you can do it like this:

-----------------------------
auth = Auth(
    session,
    db,
    define_tables=False,
    allowed_actions=["change_password", "login", "logout", "profile"]
)
auth.extra_auth_user_fields = [Field('field_1', length=25),
                               Field('field_2', length=50),
                               auth.signature]
auth.define_tables()
-----------------------------

Mamisoa Andriantafika

unread,
Feb 18, 2021, 7:03:53 AM2/18/21
to py4web
Thanks. It works perfectly.
Reply all
Reply to author
Forward
0 new messages