diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/pyramid/authentication.py | 31 | ||||
| -rw-r--r-- | src/pyramid/security.py | 31 |
2 files changed, 31 insertions, 31 deletions
diff --git a/src/pyramid/authentication.py b/src/pyramid/authentication.py index 21cfc0c0e..4f8077309 100644 --- a/src/pyramid/authentication.py +++ b/src/pyramid/authentication.py @@ -1118,6 +1118,37 @@ class SessionAuthenticationPolicy(CallbackAuthenticationPolicy): return request.session.get(self.userid_key) +class SessionAuthenticationHelper: + """ A helper for use with a :term:`security policy` which stores user data + in the configured :term:`session`. + + Constructor Arguments + + ``prefix`` + + A prefix used when storing the authentication parameters in the + session. Defaults to 'auth.'. Optional. + + """ + + def __init__(self, prefix='auth.'): + self.userid_key = prefix + 'userid' + + def remember(self, request, userid, **kw): + """ Store a userid in the session.""" + request.session[self.userid_key] = userid + return [] + + def forget(self, request): + """ Remove the stored userid from the session.""" + if self.userid_key in request.session: + del request.session[self.userid_key] + return [] + + def identify(self, request): + return request.session.get(self.userid_key) + + @implementer(IAuthenticationPolicy) class BasicAuthAuthenticationPolicy(CallbackAuthenticationPolicy): """ A :app:`Pyramid` authentication policy which uses HTTP standard basic diff --git a/src/pyramid/security.py b/src/pyramid/security.py index dda61ef27..5d157d219 100644 --- a/src/pyramid/security.py +++ b/src/pyramid/security.py @@ -540,34 +540,3 @@ class ACLHelper: allowed.update(allowed_here) return allowed - - -class SessionAuthenticationHelper: - """ A helper for use with a :term:`security policy` which stores user data - in the configured :term:`session`. - - Constructor Arguments - - ``prefix`` - - A prefix used when storing the authentication parameters in the - session. Defaults to 'auth.'. Optional. - - """ - - def __init__(self, prefix='auth.'): - self.userid_key = prefix + 'userid' - - def remember(self, request, userid, **kw): - """ Store a userid in the session.""" - request.session[self.userid_key] = userid - return [] - - def forget(self, request): - """ Remove the stored userid from the session.""" - if self.userid_key in request.session: - del request.session[self.userid_key] - return [] - - def identify(self, request): - return request.session.get(self.userid_key) |
