refresh session cookie on every page view

This commit is contained in:
codl 2017-08-09 14:28:30 +02:00
parent ea30cdd355
commit 994e0b1366
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
3 changed files with 9 additions and 4 deletions

View File

@ -2,3 +2,4 @@ from .auth import require_auth
from .interval import decompose_interval
from .interval import SCALES as interval_scales
from .cachebust import cachebust
from .session import set_session_cookie

5
lib/session.py Normal file
View File

@ -0,0 +1,5 @@
def set_session_cookie(session, response, secure=True):
response.set_cookie('forget_sid', session.id,
max_age=60*60*48,
httponly=True,
secure=secure)

View File

@ -3,6 +3,7 @@ from datetime import datetime, timedelta
import lib.twitter
import lib
from lib import require_auth
from lib import set_session_cookie
from model import Account, Session, Post, TwitterArchive
from app import app, db, sentry
import tasks
@ -31,6 +32,7 @@ def inject_version():
@app.after_request
def touch_viewer(resp):
if g.viewer:
set_session_cookie(g.viewer, resp, app.config.get('HTTPS'))
g.viewer.touch()
db.session.commit()
return resp
@ -70,10 +72,7 @@ def twitter_login_step2():
tasks.fetch_acc.s(token.account_id).apply_async(routing_key='high')
resp = Response(status=302, headers={"location": url_for('index')})
resp.set_cookie('forget_sid', session.id,
max_age=60*60*48,
httponly=True,
secure=app.config.get("HTTPS"))
set_session_cookie(session, resp, app.config.get('HTTPS'))
return resp
except (TwitterError, URLError):
return redirect(url_for('index', twitter_login_error='', _anchor='log_in'))