summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pyramid/security.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/pyramid/security.py b/src/pyramid/security.py
index bfd505a98..671cd3569 100644
--- a/src/pyramid/security.py
+++ b/src/pyramid/security.py
@@ -540,3 +540,34 @@ 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)