1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

Improved sessions handling

This commit is contained in:
Alban 2012-11-17 18:09:35 +01:00
parent 856e96c28d
commit 7dbd1f9764

15
web.py
View File

@ -9,6 +9,7 @@ app.secret_key = '?9huDM\\H'
import db import db
from scanner import Scanner from scanner import Scanner
from user_manager import UserManager
@app.before_request @app.before_request
def init_and_login_check(): def init_and_login_check():
@ -20,9 +21,17 @@ def init_and_login_check():
flash('Not configured. Please create the first admin user') flash('Not configured. Please create the first admin user')
return redirect(url_for('add_user')) return redirect(url_for('add_user'))
if not (admin_count == 0 and request.endpoint == 'add_user') and not session.get('userid') and request.endpoint != 'login': if not (admin_count == 0 and request.endpoint == 'add_user') and request.endpoint != 'login':
flash('Please login') should_login = False
return redirect(url_for('login', returnUrl = request.url[len(request.url_root)-1:])) if not session.get('userid'):
should_login = True
elif UserManager.get(session.get('userid'))[0] != UserManager.SUCCESS:
session.clear()
should_login = True
if should_login:
flash('Please login')
return redirect(url_for('login', returnUrl = request.url[len(request.url_root)-1:]))
@app.teardown_request @app.teardown_request
def teardown(exception): def teardown(exception):