refresh session cookie on every page view
This commit is contained in:
parent
ea30cdd355
commit
994e0b1366
|
@ -2,3 +2,4 @@ from .auth import require_auth
|
||||||
from .interval import decompose_interval
|
from .interval import decompose_interval
|
||||||
from .interval import SCALES as interval_scales
|
from .interval import SCALES as interval_scales
|
||||||
from .cachebust import cachebust
|
from .cachebust import cachebust
|
||||||
|
from .session import set_session_cookie
|
||||||
|
|
|
@ -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)
|
|
@ -3,6 +3,7 @@ from datetime import datetime, timedelta
|
||||||
import lib.twitter
|
import lib.twitter
|
||||||
import lib
|
import lib
|
||||||
from lib import require_auth
|
from lib import require_auth
|
||||||
|
from lib import set_session_cookie
|
||||||
from model import Account, Session, Post, TwitterArchive
|
from model import Account, Session, Post, TwitterArchive
|
||||||
from app import app, db, sentry
|
from app import app, db, sentry
|
||||||
import tasks
|
import tasks
|
||||||
|
@ -31,6 +32,7 @@ def inject_version():
|
||||||
@app.after_request
|
@app.after_request
|
||||||
def touch_viewer(resp):
|
def touch_viewer(resp):
|
||||||
if g.viewer:
|
if g.viewer:
|
||||||
|
set_session_cookie(g.viewer, resp, app.config.get('HTTPS'))
|
||||||
g.viewer.touch()
|
g.viewer.touch()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return resp
|
return resp
|
||||||
|
@ -70,10 +72,7 @@ def twitter_login_step2():
|
||||||
tasks.fetch_acc.s(token.account_id).apply_async(routing_key='high')
|
tasks.fetch_acc.s(token.account_id).apply_async(routing_key='high')
|
||||||
|
|
||||||
resp = Response(status=302, headers={"location": url_for('index')})
|
resp = Response(status=302, headers={"location": url_for('index')})
|
||||||
resp.set_cookie('forget_sid', session.id,
|
set_session_cookie(session, resp, app.config.get('HTTPS'))
|
||||||
max_age=60*60*48,
|
|
||||||
httponly=True,
|
|
||||||
secure=app.config.get("HTTPS"))
|
|
||||||
return resp
|
return resp
|
||||||
except (TwitterError, URLError):
|
except (TwitterError, URLError):
|
||||||
return redirect(url_for('index', twitter_login_error='', _anchor='log_in'))
|
return redirect(url_for('index', twitter_login_error='', _anchor='log_in'))
|
||||||
|
|
Loading…
Reference in New Issue