Created
November 16, 2012 09:23
-
-
Save mekarpeles/4085832 to your computer and use it in GitHub Desktop.
Sessions and authentication module for Waltz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
""" | |
auth.py | |
~~~~~~~ | |
Sessions and authentication | |
""" | |
def initialize_session(web, app, storage_method, **kwargs): | |
web.config.session_parameters['ignore_expiry'] = False | |
def default_session(web_session): | |
default_session = {'logged': False, | |
'username': '', | |
} | |
web_session.update(default_session) | |
session = web.session.Session(app, storage_method, initializer=default_session) | |
def session_hook(): | |
"""Expose variables to subapps""" | |
web.ctx.session = {session} | |
session_hook = kwargs.setdefault('hook', session_hook) | |
app.add_processor(web.loadhook(session_hook)) | |
return session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment