On Wednesday, December 28, 2011 9:18:07 AM UTC-5, david.waldrop wrote:
>
> I have the following auth.settings :
>
> # log system events
> auth.settings.login_onaccept = lambda form:logactivity('Login','none')
> auth.settings.profile_onaccept = lambda form:logactivity('Update 
> Profile','none')
> auth.settings.register_onaccept = lambda 
> form:logactivity('Register','none')
>
>
> which call the following function:
>
> def logactivity(action, details):
>     db.log.insert(action=action, details=details)
>     return True
>
>
> The log table is defined as follows:
>
> #----------------------Log-------------------------------         
> db.define_table('log',
>     Field('action'),
>     Field('details'),
>     Field('created_by',db.auth_user,readable=False,writable=False),
>     Field('created_on','datetime',default=request.now, 
> readable=False,writable=False),
>     migrate=migrate_db)
> db.log.action.requires = IS_NOT_EMPTY()
> db.log.details.requires = IS_NOT_EMPTY()
> if auth.is_logged_in():
>    db.log.created_by.default = auth.user.id  
>
>
> The problem is the *created_by* field is not being set to the logged in 
> user, but rather non.  The weird thing is the *created_on* is being set 
> properly.  I suspect this has something to do with timing, but the 
> documentation says onaccept happens after IO so I expected the auth.user 
> object to be fully populated.  And ideas how I can fix this so the login 
> action is logged in the table?
>

You check if the user is logged in in the model file, but the user isn't 
actually logged in until later, after the controller processes the login 
credentials. Anyway, are you aware of the auth_event table -- the Auth 
system already logs all Auth activity in that table? 
See http://web2py.com/books/default/chapter/29/9#Access-Control.

Anthony

Reply via email to