Ejemplo n.º 1
0
    def decorated_function(*args, **kwargs):
        authenticated = False

        if g.user.id is not None:
            authenticated = True

        elif request.authorization is not None:
            user = User.authenticate(request.authorization['username'],
                                     request.authorization['password'])
            if user is not None:
                g.user = user
                authenticated=True

        elif 'authorization' in request.headers:
            match = api_key_re.match(request.headers['authorization'])
            if match:
                user, device = Device.authenticate(match.group(1))
                if user is not None:
                    g.user = user
                    g.device = device
                    authenticated = True

        if authenticated:
            return f(*args, **kwargs)
        abort(403)