forget-cancellare-vecchi-toot/lib/session.py

23 lines
475 B
Python
Raw Normal View History

2017-08-10 17:07:39 +02:00
from flask import request
2017-08-29 14:46:32 +02:00
def set_session_cookie(session, response, secure=True):
2017-08-29 14:46:32 +02:00
response.set_cookie(
'forget_sid', session.id,
max_age=60*60*48,
httponly=True,
secure=secure)
2017-08-10 17:07:39 +02:00
2017-08-29 14:46:32 +02:00
2017-08-10 17:07:39 +02:00
def get_viewer_session():
from model import Session
sid = request.cookies.get('forget_sid', None)
if sid:
return Session.query.get(sid)
2017-08-29 14:46:32 +02:00
2017-08-10 17:07:39 +02:00
def get_viewer():
session = get_viewer_session()
if session:
return session.account