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 import config
app = create_app()

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

@ -9,12 +9,10 @@ from datetime import datetime
from wowstash import config
app = None
db = None
bcrypt = None
db = SQLAlchemy()
bcrypt = Bcrypt()
def _setup_db(app: Flask):
global db
uri = 'postgresql+psycopg2://{user}:{pw}@{host}:{port}/{db}'.format(
user=config.DB_USER,
pw=config.DB_PASS,
@ -28,34 +26,18 @@ def _setup_db(app: Flask):
import wowstash.models
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():
global app
global db
global bcrypt
global login_manager
app = Flask(__name__)
app.config.from_envvar('FLASK_SECRETS')
app.secret_key = app.config['SECRET_KEY']
# Setup backends
_setup_db(app)
_setup_session(app)
_setup_bcrypt(app)
CSRFProtect(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
with app.app_context():
login_manager = LoginManager()
login_manager.init_app(app)
# Login manager
login_manager.login_view = 'auth.login'
login_manager.logout_view = 'auth.logout'
@ -65,7 +47,7 @@ def create_app():
user = User.query.get(user_id)
return user
# template filters
# Template filters
@app.template_filter('datestamp')
def datestamp(s):
d = datetime.fromtimestamp(s)
@ -80,12 +62,13 @@ def create_app():
else:
return float(atomic)
# CLI
@app.cli.command('clean_containers')
def clean_containers():
from wowstash.library.docker import docker
docker.cleanup()
# Routes
# Routes/blueprints
from wowstash.blueprints.auth import auth_bp
from wowstash.blueprints.wallet import wallet_bp
from wowstash.blueprints.meta import meta_bp
@ -93,5 +76,4 @@ def create_app():
app.register_blueprint(auth_bp)
app.register_blueprint(wallet_bp)
app.app_context().push()
return app

Loading…
Cancel
Save