aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authentication/checks.py
blob: 63b0752d21d65a11b2fb1cabcd1b870558b7fc2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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__