I am using pam_auth login for my web2py installation. When a user logs in for the first time, I want to store his email which i obtain from a ldap query. How 开发者_开发知识库can I do that in web2py.
In other words, i want to execute a piece of ldap query in python at the time of first login by any user.
web2py default authentication system has an event table, which stores every event for the user. i.e it stores events for registration, login, logout, etc.
So you can see if it is the first time login by querying this table.
USER_ID = #Get your user ID
query = (db.auth_event.description.like('%Logged-in%'))&(db.auth_event.user_id==USER_ID)
if db(query).count() == 1:
#this is the first login of this user
ldap_mail = #Call LDAP to get the email
#store the email adress in auth_user
db(db.auth_user.id==USER_ID).update(email=ldap_mail)
精彩评论