#12 Event API

1.5.1
open
nobody
None
identity
enhancement
normal
2014-01-17
2011-03-11
No

This was ticket #754 on the old Trac, suggested by Claudio Martinez in 2006:

It would be nice to have the posibility to add functions to certain identity events.

One example:

import identity

def login_succesful(user):
    # setup some session data

identity.on_sucess.append(login_successful)

Would help clear a lot of redundant code from controllers.

Discussion

  • Patch contributed by Claudio Martinez 04/17/06:

    Attached is a patch that adds some event handling to identity using a generic event system. It's very, very simple, and other parts of turbogears can add events too.

    I'm using this right now and works for me. I want to share this with other people that ran into the same limitations I did. There's no way of doing this without modding identity.

    Example:

    import turbogears
    
    def _on_logout(d):
        # clear session data
    turbogears.events['identity']['on_logout'].append(_on_logout)
    
    def _on_success(d):
        # setup some session data
    turbogears.events['identity']['on_success'].append(_on_success)
    
    def _on_failure(d):
        # audit
    turbogears.events['identity']['on_failure'].append(_on_failure)
    
    def _before_validation(d):
        # mangle username or password if you like
    turbogears.events['identity']['before_validation'].append(_before_validation)
    
    def _after_validation(d):
        # audit
    turbogears.events['identity']['after_validation'].append(_after_validation)
    

    d has the keys user_name, pw, visit_key and, depending if the login was succesful, identity.

    In the patch I moved some stuff out of a try: except: block because it was only there to catch some KeyError?'s from some pops and it was executing the validation method inside it, complicating debugging. Someone may want to open a separate ticket for this, anyone developing a new identity provider will thank you :)

     
    Attachments


Anonymous


Cancel   Add attachments