From 98f0fcdcbdbbd91a2a4da6b44229a178ddb38d31 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Tue, 26 Mar 2019 16:17:11 +0000 Subject: Add support for email confirmation --- app/decorators.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 app/decorators.py (limited to 'app/decorators.py') diff --git a/app/decorators.py b/app/decorators.py new file mode 100644 index 0000000..d5b8821 --- /dev/null +++ b/app/decorators.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- + +from functools import wraps + +from flask import current_app, request, redirect, flash, url_for +from flask_login import current_user +from flask_login.config import EXEMPT_METHODS + + +def admin_required(func): + @wraps(func) + def decorated_view(*args, **kwargs): + if request.method in EXEMPT_METHODS: + return func(*args, **kwargs) + elif current_app.config.get("LOGIN_DISABLED"): + return func(*args, **kwargs) + elif not current_user.is_authenticated: + return current_app.login_manager.unauthorized() + elif not current_user.is_admin: + return current_app.login_manager.unauthorized() + return func(*args, **kwargs) + + return decorated_view + + +def login_required(func): + @wraps(func) + def decorated_view(*args, **kwargs): + if request.method in EXEMPT_METHODS: + return func(*args, **kwargs) + elif current_app.config.get("LOGIN_DISABLED"): + return func(*args, **kwargs) + elif not current_user.is_authenticated: + return current_app.login_manager.unauthorized() + elif not current_user.is_confirmed: + flash("hello world") + return redirect(url_for("auth.not_confirmed")) + return func(*args, **kwargs) + + return decorated_view -- cgit v1.2.3