summaryrefslogtreecommitdiff
path: root/service/pixelated/resources/session.py
diff options
context:
space:
mode:
authorRoald de Vries <rdevries@thoughtworks.com>2016-12-07 15:26:10 +0100
committerRoald de Vries <rdevries@thoughtworks.com>2016-12-07 15:26:10 +0100
commitd10f607a4d40587510b0dc31b31fe4750bf4a3a3 (patch)
treedb016bb0878989249e0f329e2162d11067b0f8b7 /service/pixelated/resources/session.py
parentc28abba2f5b1186c671ebef508d40ffaae6d5bc5 (diff)
parenteaf2019b6e977d1191e0ee12f694a02bb9612f83 (diff)
[#801] Merge branch 'signup'
Diffstat (limited to 'service/pixelated/resources/session.py')
-rw-r--r--service/pixelated/resources/session.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/service/pixelated/resources/session.py b/service/pixelated/resources/session.py
index 9ade8d29..0e46ad8f 100644
--- a/service/pixelated/resources/session.py
+++ b/service/pixelated/resources/session.py
@@ -13,11 +13,15 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+import hashlib
+import os
from zope.interface import Interface, Attribute, implements
from twisted.python.components import registerAdapter
from twisted.web.server import Session
+CSRF_TOKEN_LENGTH = 32
+
class IPixelatedSession(Interface):
user_uuid = Attribute('The uuid of the currently logged in user')
@@ -28,6 +32,7 @@ class PixelatedSession(object):
def __init__(self, session):
self.user_uuid = None
+ self._csrf_token = None
def is_logged_in(self):
return self.user_uuid is not None
@@ -35,5 +40,10 @@ class PixelatedSession(object):
def expire(self):
self.user_uuid = None
+ def get_csrf_token(self):
+ if self._csrf_token is None:
+ self._csrf_token = hashlib.sha256(os.urandom(CSRF_TOKEN_LENGTH)).hexdigest()
+ return self._csrf_token
+
registerAdapter(PixelatedSession, Session, IPixelatedSession)