fix cookie/session issues

mm-logging
lza_menace 4 years ago
parent a41aa23282
commit 3674712998

@ -1,4 +1,5 @@
from wowstash.factory import create_app from wowstash.factory import create_app
from wowstash import config
app = create_app() app = create_app()

@ -18,11 +18,13 @@ SECRET_KEY = 'secret session key here' # encrypts the session token
# Session # Session
PERMANENT_SESSION_LIFETIME = 1800 # 60 minute session expiry PERMANENT_SESSION_LIFETIME = 1800 # 60 minute session expiry
SESSION_TYPE = 'redis'
SESSION_COOKIE_NAME = 'wowstash' SESSION_COOKIE_NAME = 'wowstash'
SESSION_COOKIE_DOMAIN = '127.0.0.1'
SESSION_COOKIE_SECURE = False SESSION_COOKIE_SECURE = False
SESSION_USE_SIGNER = True SESSION_USE_SIGNER = True
SESSION_PERMANENT = True SESSION_PERMANENT = True
# Redis
REDIS_HOST = 'localhost' REDIS_HOST = 'localhost'
REDIS_PORT = 6379 REDIS_PORT = 6379

@ -9,12 +9,10 @@ from datetime import datetime
from wowstash import config from wowstash import config
app = None db = SQLAlchemy()
db = None bcrypt = Bcrypt()
bcrypt = None
def _setup_db(app: Flask): def _setup_db(app: Flask):
global db
uri = 'postgresql+psycopg2://{user}:{pw}@{host}:{port}/{db}'.format( uri = 'postgresql+psycopg2://{user}:{pw}@{host}:{port}/{db}'.format(
user=config.DB_USER, user=config.DB_USER,
pw=config.DB_PASS, pw=config.DB_PASS,
@ -28,70 +26,54 @@ def _setup_db(app: Flask):
import wowstash.models import wowstash.models
db.create_all() db.create_all()
def _setup_session(app: Flask):
app.config['SESSION_REDIS'] = Redis(
host=app.config['REDIS_HOST'],
port=app.config['REDIS_PORT']
)
Session(app)
def _setup_bcrypt(app: Flask):
global bcrypt
bcrypt = Bcrypt(app)
def create_app(): def create_app():
global app
global db
global bcrypt
global login_manager
app = Flask(__name__) app = Flask(__name__)
app.config.from_envvar('FLASK_SECRETS') app.config.from_envvar('FLASK_SECRETS')
app.secret_key = app.config['SECRET_KEY']
# Setup backends # Setup backends
_setup_db(app) _setup_db(app)
_setup_session(app) bcrypt = Bcrypt(app)
_setup_bcrypt(app) login_manager = LoginManager(app)
CSRFProtect(app)
with app.app_context():
login_manager = LoginManager() # Login manager
login_manager.init_app(app) login_manager.login_view = 'auth.login'
login_manager.login_view = 'auth.login' login_manager.logout_view = 'auth.logout'
login_manager.logout_view = 'auth.logout'
@login_manager.user_loader @login_manager.user_loader
def load_user(user_id): def load_user(user_id):
from wowstash.models import User from wowstash.models import User
user = User.query.get(user_id) user = User.query.get(user_id)
return user return user
# template filters # Template filters
@app.template_filter('datestamp') @app.template_filter('datestamp')
def datestamp(s): def datestamp(s):
d = datetime.fromtimestamp(s) d = datetime.fromtimestamp(s)
return d.strftime('%Y-%m-%d %H:%M:%S') return d.strftime('%Y-%m-%d %H:%M:%S')
@app.template_filter('from_atomic') @app.template_filter('from_atomic')
def from_atomic(a): def from_atomic(a):
from wowstash.library.jsonrpc import from_atomic from wowstash.library.jsonrpc import from_atomic
atomic = from_atomic(a) atomic = from_atomic(a)
if atomic == 0: if atomic == 0:
return 0 return 0
else: else:
return float(atomic) return float(atomic)
@app.cli.command('clean_containers') # CLI
def clean_containers(): @app.cli.command('clean_containers')
from wowstash.library.docker import docker def clean_containers():
docker.cleanup() from wowstash.library.docker import docker
docker.cleanup()
# Routes # Routes/blueprints
from wowstash.blueprints.auth import auth_bp from wowstash.blueprints.auth import auth_bp
from wowstash.blueprints.wallet import wallet_bp from wowstash.blueprints.wallet import wallet_bp
from wowstash.blueprints.meta import meta_bp from wowstash.blueprints.meta import meta_bp
app.register_blueprint(meta_bp) app.register_blueprint(meta_bp)
app.register_blueprint(auth_bp) app.register_blueprint(auth_bp)
app.register_blueprint(wallet_bp) app.register_blueprint(wallet_bp)
app.app_context().push() return app
return app

Loading…
Cancel
Save