summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTheron Luhn <theron@luhn.com>2019-03-30 10:31:17 -0700
committerTheron Luhn <theron@luhn.com>2019-03-30 10:31:17 -0700
commit6aba89d19cc384021864d3b83d53082f56c3f419 (patch)
treeb58eb5b0ada99abdfe12108eb3ad1f6b8664a82a /src
parent31998bcdd0396316c1a0fdeb50bee59e4b9e14ed (diff)
downloadpyramid-6aba89d19cc384021864d3b83d53082f56c3f419.tar.gz
pyramid-6aba89d19cc384021864d3b83d53082f56c3f419.tar.bz2
pyramid-6aba89d19cc384021864d3b83d53082f56c3f419.zip
Add SessionAuthenticationHelper.
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)