Hi Massimo,
I will try to explain better, posting the annotated code below.
I want to define the *auth_user* in a module and configure it as:
==============================================================
Configuration
==============================================================
db.auth_user.first_name.writable = db.auth_user.first_name.readable
= False
db.auth_user.last_name.writable = db.auth_user.last_name.readable
=False
# get rid of "please input your password again"
auth.messages.verify_password_comment = ''
==============================================================
e.g. to not show the first, last name and to not see "verify password".
*
*
I am using to custom import Main in *user(). *Main executes *common_services
* which executes *init_auth*, which
executes *define_auth*, where *auth_user* is defined and should be
configured (Configuration). Configuration do not works
in *define_auth, *but works in* **init_auth *in the code below. I believe
the code in *define_auth * called in *init_auth as "*self.*auth_def*()
#the auth definition", never executes so I have to do it in *init_auth.*
*
*
*Regards,*
*--Constantine*
*
*
*controllers/default.py*
# -*- coding: utf-8 -*-
### required - do no delete
def *user*():
from main import Main
current.app.myapp = Main()
current.app.myapp.*common_services*()
return dict(form=current.app.auth())
*modules/main.py*
#!/usr/bin/env python
# coding: utf8
from gluon import *
class Main(object):
def __init__(self):
self.auth_def = lambda: self.define_auth
def connect_to_db(self):
response = current.response
request = current.request
session = current.session
#connect to db
if request.env.web2py_runtime_gae: # if running on Google
App Engine
current.app.db = DAL('gae') # connect
to Google BigTable
session.connect(request, response, db = current.app.db) # and
store sessions and tickets there
else: # else use a normal
relational database
current.app.db = DAL(current.app.settings.database_uri) #
if not, use SQLite or other DB
return current.app.db
def init_service(self):
from gluon.tools import Service
current.app.service = Service()
return current.app.service
def *init_auth*(self):
from gluon.tools import Auth
settings = current.app.settings
request = current.request
auth = Auth(current.app.db) #authentication/authorization
auth.settings.hmac_key = settings.security_key # before
define_tables()
self.*auth_def*() #the auth definition
auth.define_tables(migrate=settings.migrate) # creates all needed
tables
db = current.app.db
###########################################################################
# config - these statements below *do work here*, but do not id
executed in *define_table*
###########################################################################
db.auth_user.first_name.writable = db.auth_user.first_name.readable
= False
db.auth_user.last_name.writable = db.auth_user.last_name.readable
=False
# get rid of "please input your password again"
auth.messages.verify_password_comment = ''
###########################################################################
def *define_auth*(self):
# called in init_auth
db = current.app.db
request = current.request
settings = current.app.settings
auth = current.app.auth
#Add your own users fields
db.*define_table*('*auth_user*',
Field('id','id',
represent=lambda id:SPAN(id,'
',A('view',_href=URL('auth_user_read',args=id)))),
Field('username', type='string',
label=T('Username')),
Field('first_name', type='string',
label=T('First Name')),
Field('last_name', type='string',
label=T('Last Name')),
Field('email', type='string',
label=T('Email')),
Field('password', type='password',
readable=False,
label=T('Password')),
Field('created_on','datetime',default=request.now,
label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
label=T('Modified On'),writable=False,readable=False,
update=request.now),
Field('registration_key',default='',
writable=False,readable=False),
Field('reset_password_key',default='',
writable=False,readable=False),
Field('registration_id',default='',
writable=False,readable=False),
format='%(username)s',
migrate=settings.migrate)
#auth.define_tables(username=False)
#db.auth_user.first_name.requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
#db.auth_user.last_name.requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db,
db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db,
db.auth_user.registration_id)
db.auth_user.email.requires =
(IS_EMAIL(error_message=auth.messages.invalid_email),
IS_NOT_IN_DB(db, db.auth_user.email))
###########################################################################
# config - these statements below *do not work here*, need ot be
executed in *init_auth*
###########################################################################
db.auth_user.first_name.writable = db.auth_user.first_name.readable
= False
db.auth_user.last_name.writable = db.auth_user.last_name.readable
=False
# get rid of "please input your password again"
auth.messages.verify_password_comment = ''
###########################################################################
def *common_services*(self):
from gluon.tools import PluginManager
self.connect_to_db()
self.*init_auth*()
self.init_service()
current.app.plugins = PluginManager() #init the plugin manager,
first of all plugins.