Wsgi_15Watt.BaseController

 1from .Request import Request
 2from .Response import Response
 3from .Exceptions import Unauthorized
 4
 5
 6def decoratorLoginRequired(func):
 7	"""
 8		A decorator for controller methods, that checks if the user has logged in via BasicAuth.
 9
10		If not so, a 401 Unauthorized exception is raised.
11	"""
12	def wrapper(self, request: Request, response: Response):
13		if 'Basic' != request.getEnvByKey('AUTH_TYPE'):
14			# Send a 401 response as plain/text, not a exception/500er
15			raise Unauthorized(
16				returnCode=401,
17				returnMsg=f"Invalid auth type: {request.getEnvByKey('AUTH_TYPE')}"
18			)
19
20		if request.getEnvByKey('REMOTE_USER') is None:
21			raise Unauthorized(returnCode=401, returnMsg='Unauthorized')
22
23		return func(self, request, response)
24	return wrapper
25
26
27class BaseController(object):
28	"""
29		Basisklasse of all controllers.
30	"""
31	def __init__(self, config: dict):
32		self._config = config
def decoratorLoginRequired(func):
 7def decoratorLoginRequired(func):
 8	"""
 9		A decorator for controller methods, that checks if the user has logged in via BasicAuth.
10
11		If not so, a 401 Unauthorized exception is raised.
12	"""
13	def wrapper(self, request: Request, response: Response):
14		if 'Basic' != request.getEnvByKey('AUTH_TYPE'):
15			# Send a 401 response as plain/text, not a exception/500er
16			raise Unauthorized(
17				returnCode=401,
18				returnMsg=f"Invalid auth type: {request.getEnvByKey('AUTH_TYPE')}"
19			)
20
21		if request.getEnvByKey('REMOTE_USER') is None:
22			raise Unauthorized(returnCode=401, returnMsg='Unauthorized')
23
24		return func(self, request, response)
25	return wrapper

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

If not so, a 401 Unauthorized exception is raised.

class BaseController:
28class BaseController(object):
29	"""
30		Basisklasse of all controllers.
31	"""
32	def __init__(self, config: dict):
33		self._config = config

Basisklasse of all controllers.

BaseController(config: dict)
32	def __init__(self, config: dict):
33		self._config = config