Skip to content

Commit

Permalink
Adds before and after login view call hooks, which are useful for sys…
Browse files Browse the repository at this point in the history
…tems using velruse as a plugin. It allows the plugin user to modify any information before or after the login view is called. For example, before or after the login view is hit, one could capture the referrer location so that they can send the authenticated user back to where they came from.
  • Loading branch information
mmulich committed Jun 1, 2013
1 parent 0fd031d commit 7b52085
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions velruse/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""Custom events for identity provider login."""
import functools
from pyramid.events import NewRequest

def with_events(before=None, after=None):
"""Decorator to create event book ends on a method."""
def decorator(method):
@functools.wraps(method)
def new_method(obj, request):
request.registry.notify(before(request))
response = method(obj, request)
request.registry.notify(after(request))
return response
return new_method
return decorator


class BeforeLogin(NewRequest):
"""Used to tap into the request before
the identity provider logic is run.
"""


class AfterLogin(NewRequest):
"""Used to tap into the request after
the identity provider logic has run.
"""
2 changes: 2 additions & 0 deletions velruse/providers/openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
AuthenticationDenied,
register_provider,
)
from velruse.events import with_events, AfterLogin, BeforeLogin
from velruse.exceptions import MissingParameter
from velruse.exceptions import ThirdPartyFailure

Expand Down Expand Up @@ -180,6 +181,7 @@ def _get_access_token(self, request_token):
"""

@with_events(before=BeforeLogin, after=AfterLogin)
def login(self, request):
log.debug('Handling OpenID login')

Expand Down

0 comments on commit 7b52085

Please sign in to comment.