Monday, November 21, 2011

web2py: hide register link on page

The following code will hide the link but also disable the function to register user completely even you create the record from appadmin menu.

auth.settings.actions_disabled=['register']

So here's how I do...

# all we need is login
auth.settings.actions_disabled=['change_password','request_reset_password','retrieve_username','profile']
if request.controller != 'appadmin':
    auth.settings.actions_disabled +=['register']

In this way, it's disabled for users but not admin.

web2py: add additonal field in auth_user

It's actually very easy. Just add the following code in your model before auth.define_tables().



## additonal fields
auth.settings.extra_fields['auth_user']= [
  Field('office')
  ]

So it will be like this...

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()

## create all tables needed by auth if not custom tables
## additonal fields
auth.settings.extra_fields['auth_user']= [
  Field('office')
  ]
auth.define_tables()