/
auth_policy.py
25 lines (21 loc) · 1003 Bytes
/
auth_policy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# lolreg package
# -------------------------------------------------------------
from pyramid.interfaces import IAuthenticationPolicy
from zope.interface import implements
class LolRegAuthenticationPolicy(object):
implements(IAuthenticationPolicy)
def __init__(self, backend):
self.backend = backend
def authenticated_userid(self, request):
# use self.backend to figure out who the guy is and if he exists
pass
# .. other IAuthenticationPolicy methods ...
def includeme(config):
settings = config.settings
backend_factory = settings.get('lolreg.backend_factory',
'lolreg.sqla.SQLARegistrationBackend')
backend_factory = config.maybe_dotted(backend_factory)
backend = backend_factory(settings)
config.add_route('lolreg.register', '/register', factory=backend)
config.add_route('lolreg.activate', '/activate', factory=backend)
config.set_authentication_policy(LolRegAuthenticationPolicy(backend))