Thanks for pointing me in the right direction, Stifan.

I added this line to the model file:
db.auth_user._after_update.append(lambda s: remove_mobile_token(s, db))

and this function in a module

def remove_mobile_token(set, db):
    request = current.request
    
    #delete mobile tokens if the change IS NOT from reset_password
    if request.function == "user" and request.args>0 and request.args(0)==
"reset_password" :
        user_id = set.select().first().id
        db(db.mobile_tokens.username==user_id).delete()
        db.commit()

I tried using the f variable from the after_update callback (containing 
dictionary of fields to be updated) to check for existence of "password" in 
f, but changes to the auth_user table using auth.profile() form contains 
all the fields for auth_user, thus any changes using the auth.profile() 
form would trigger a mobile_token deletion.

To make sure only changes to the password field would trigger mobile_token 
deletion, I check that the request is coming from the user/reset_password.

On Wednesday, November 6, 2013 4:51:33 AM UTC-8, 黄祥 wrote:
>
> i think you can achieve it using after_update callback. define 
> after_update function for auth_user to delete the mobile_tokens row that 
> associated with user.
>
> ref:
>
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#before-and-after-callbacks
>
> best regards,
> stifan
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to