Module 15Watt_Wsgi.BaseController

Expand source code
from .Request import Request
from .Response import Response
from .Exceptions import Unauthorized


def decoratorLoginRequired(func):
        """
                A decorator for controller methods, that checks if the user has logged in via BasicAuth.

                If not so, a 401 Unauthorized exception is raised.
        """
        def wrapper(self, request: Request, response: Response):
                if 'Basic' != request.getEnvByKey('AUTH_TYPE'):
                        raise Unauthorized(
                                returnCode=401,
                                returnMsg=f"Invalid auth type: {request.getEnvByKey('AUTH_TYPE')}"
                        )

                if request.getEnvByKey('REMOTE_USER') is None:
                        raise Unauthorized(returnCode=401, returnMsg='Unauthorized')

                return func(self, request, response)
        return wrapper


class BaseController(object):
        """
                Basisklasse of all controllers.
        """
        def __init__(self, config: dict):
                self._config = config

Functions

def decoratorLoginRequired(func)

A decorator for controller methods, that checks if the user has logged in via BasicAuth.

If not so, a 401 Unauthorized exception is raised.

Expand source code
def decoratorLoginRequired(func):
        """
                A decorator for controller methods, that checks if the user has logged in via BasicAuth.

                If not so, a 401 Unauthorized exception is raised.
        """
        def wrapper(self, request: Request, response: Response):
                if 'Basic' != request.getEnvByKey('AUTH_TYPE'):
                        raise Unauthorized(
                                returnCode=401,
                                returnMsg=f"Invalid auth type: {request.getEnvByKey('AUTH_TYPE')}"
                        )

                if request.getEnvByKey('REMOTE_USER') is None:
                        raise Unauthorized(returnCode=401, returnMsg='Unauthorized')

                return func(self, request, response)
        return wrapper

Classes

class BaseController (config: dict)

Basisklasse of all controllers.

Expand source code
class BaseController(object):
        """
                Basisklasse of all controllers.
        """
        def __init__(self, config: dict):
                self._config = config

Subclasses