Skip to content

Instantly share code, notes, and snippets.

@dennismonsewicz
Created June 18, 2014 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennismonsewicz/b8c6093da0a5682e05cd to your computer and use it in GitHub Desktop.
Save dennismonsewicz/b8c6093da0a5682e05cd to your computer and use it in GitHub Desktop.
blueprint = Blueprint('client', __name__, template_folder='templates')
@blueprint.before_request
def load_session_from_cookie():
if request.endpoint != 'client.me':
try:
cookie = request.cookies.get(settings.COOKIE_NAME, None)
# if cookie does not exist, redirect to login url
if not cookie:
session.pop('accountId', None)
return redirect(settings.LOGIN_URL)
account = check_sso_cookie(cookie)
if 'accountId' in session:
return
elif 'accountId' in account:
session['accountId'] = account.get('accountId')
return
else:
session.pop('accountId', None)
return redirect(settings.LOGIN_URL)
except BadSignature:
session.pop('accountId', None)
return redirect(settings.LOGIN_URL)
@blueprint.route('/')
def home():
session.permanent = True
return render_template('index.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment