consolidate lib.session and lib.auth into lib.auth
This commit is contained in:
parent
93ab3294ce
commit
d851f562e4
2
app.py
2
app.py
|
@ -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
|
||||||
|
|
||||||
|
|
21
lib/auth.py
21
lib/auth.py
|
@ -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
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue