consolidate lib.session and lib.auth into lib.auth

This commit is contained in:
codl 2017-09-04 20:24:42 +02:00
parent 93ab3294ce
commit d851f562e4
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
4 changed files with 24 additions and 25 deletions

2
app.py
View File

@ -6,7 +6,7 @@ from flask_migrate import Migrate
import version import version
from lib.cachebust import cachebust from lib.cachebust import cachebust
from flask_limiter import Limiter from flask_limiter import Limiter
from lib.session import get_viewer from lib.auth import get_viewer
import os import os
import mimetypes import mimetypes

View File

@ -29,3 +29,24 @@ def csrf(fun):
return abort(403) return abort(403)
return fun(*args, **kwargs) return fun(*args, **kwargs)
return wrapper return wrapper
def set_session_cookie(session, response, secure=True):
response.set_cookie(
'forget_sid', session.id,
max_age=60*60*48,
httponly=True,
secure=secure)
def get_viewer_session():
from model import Session
sid = request.cookies.get('forget_sid', None)
if sid:
return Session.query.get(sid)
def get_viewer():
session = get_viewer_session()
if session:
return session.account

View File

@ -1,22 +0,0 @@
from flask import request
def set_session_cookie(session, response, secure=True):
response.set_cookie(
'forget_sid', session.id,
max_age=60*60*48,
httponly=True,
secure=secure)
def get_viewer_session():
from model import Session
sid = request.cookies.get('forget_sid', None)
if sid:
return Session.query.get(sid)
def get_viewer():
session = get_viewer_session()
if session:
return session.account

View File

@ -3,8 +3,8 @@ from flask import render_template, url_for, redirect, request, g, Response,\
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
import lib.twitter import lib.twitter
import lib.mastodon import lib.mastodon
from lib.auth import require_auth, require_auth_api, csrf from lib.auth import require_auth, require_auth_api, csrf,\
from lib.session import set_session_cookie, get_viewer_session, get_viewer set_session_cookie, get_viewer_session, get_viewer
from model import Session, TwitterArchive, MastodonApp, MastodonInstance from model import Session, TwitterArchive, MastodonApp, MastodonInstance
from app import app, db, sentry, limiter from app import app, db, sentry, limiter
import tasks import tasks