Flask app progress
This commit is contained in:
parent
c4fe022d42
commit
b0994069ad
38 changed files with 6631 additions and 220 deletions
21
docker/router-dash/app/auth.py
Normal file
21
docker/router-dash/app/auth.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from flask import session, redirect, flash
|
||||
from functools import wraps
|
||||
|
||||
LEVEL_RANK = {'nothing': 0, 'viewer': 1, 'administrator': 2, 'manager': 3}
|
||||
|
||||
|
||||
def require_level(minimum):
|
||||
"""Decorator that enforces a minimum access level on an action route."""
|
||||
def decorator(f):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
current = session.get('access_level', 'nothing')
|
||||
if LEVEL_RANK.get(current, 0) < LEVEL_RANK.get(minimum, 0):
|
||||
if current == 'nothing':
|
||||
flash('Please log in to continue.', 'error')
|
||||
return redirect('/view/view_log_in')
|
||||
flash('You do not have permission to perform this action.', 'error')
|
||||
return redirect('/view/view_overview')
|
||||
return f(*args, **kwargs)
|
||||
return wrapper
|
||||
return decorator
|
||||
Loading…
Add table
Add a link
Reference in a new issue