aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authentication/checks.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/auth/authentication/checks.py')
-rw-r--r--gn3/auth/authentication/checks.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/gn3/auth/authentication/checks.py b/gn3/auth/authentication/checks.py
new file mode 100644
index 0000000..63b0752
--- /dev/null
+++ b/gn3/auth/authentication/checks.py
@@ -0,0 +1,14 @@
+"""Functions to check for user authentication."""
+
+from flask import g
+
+from .exceptions import AuthenticationError
+
+def authenticated_p(func):
+ """Decorator for functions requiring authentication."""
+ def __authenticated__(*args, **kwargs):
+ user = g.user if hasattr(g, "user") else False
+ if user:
+ return func(*args, **kwargs)
+ raise AuthenticationError("You need to be authenticated")
+ return __authenticated__