mirror of
https://github.com/StefBuwalda/WebTech.git
synced 2025-10-30 11:19:58 +00:00
Added decorator for admin
This commit is contained in:
16
application/decorators.py
Normal file
16
application/decorators.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from flask_login import current_user
|
||||
from functools import wraps
|
||||
from flask import redirect, url_for, flash
|
||||
|
||||
|
||||
def admin_required(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if not current_user.is_authenticated:
|
||||
return redirect(url_for("login"))
|
||||
if not current_user.is_admin:
|
||||
flash("Admins only!")
|
||||
return redirect(url_for("index"))
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return decorated_function
|
||||
Reference in New Issue
Block a user