parameters: (self, check, required, realm="private", text="Access denied")
return_statement: return decorator
docstring: Callback decorator to require HTTP auth (basic).
          TODO: Add route(check_auth=...) parameter.
docstring_summary: Callback decorator to require HTTP auth (basic).
          TODO: Add route(check_auth=...) parameter.
docstring_tokens: Callback decorator to require HTTP auth ( basic ) . TODO : Add route ( check_auth = ... ) parameter .
function: def __auth_basic(self, check, required, realm="private", text="Access denied"):
      """ Callback decorator to require HTTP auth (basic).
          TODO: Add route(check_auth=...) parameter. """
  
      def decorator(func):
  
        @functools.wraps(func)
        def wrapper(*a, **ka):
          if int(self.engine.settings['always_authenticate']) != -1 and (required or terrariumUtils.is_true(self.engine.settings['always_authenticate'])):
            user, password = request.auth or (None, None)
            ip = request.remote_addr if request.get_header('X-Real-Ip') is None else request.get_header('X-Real-Ip')
            if user is None or not check(user, password):
              err = HTTPError(401, text)
              err.add_header('WWW-Authenticate', f'Basic realm="{realm}"')
              if user is not None or password is not None:
                #self.engine.notification.message('authentication_warning',{'ip' : ip, 'username' : user, 'password' : password},[])
                logger.warning(f'Incorrect login detected using username \'{user}\' and password \'{password}\' from ip {ip}')
              return err
  
          if request.method.lower() in ['get','head']:
            self.__add_caching_headers(response,request.fullpath)
  
            if request.url.lower().endswith('.html') or '/' == request.fullpath:
              user, password = request.get_cookie('auth', secret=self.cookie_secret) or (None, None)
              if check(user, password):
                # Update the cookie timeout so that we are staying logged in as long as we are working on the interface
                response.set_cookie('auth', request.get_cookie('auth', secret=self.cookie_secret), secret=self.cookie_secret, **{ 'max_age' : 3600, 'path' : '/'})
  
          elif request.method.lower() in ['post','put','delete']:
            response.set_cookie('no-cache','1', secret=None, **{ 'max_age' : 90, 'path' : '/'})
            response.set_header('Cache-Control', 'no-cache')
  
  
          return func(*a, **ka)
  
        return wrapper
  
      return decorator
function_tokens: def __auth_basic ( self , check , required , realm = "private" , text = "Access denied" ) : def decorator ( func ) : @ functools . wraps ( func ) def wrapper ( * a , * * ka ) : if int ( self . engine . settings [ 'always_authenticate' ] ) != - 1 and ( required or terrariumUtils . is_true ( self . engine . settings [ 'always_authenticate' ] ) ) : user , password = request . auth or ( None , None ) ip = request . remote_addr if request . get_header ( 'X-Real-Ip' ) is None else request . get_header ( 'X-Real-Ip' ) if user is None or not check ( user , password ) : err = HTTPError ( 401 , text ) err . add_header ( 'WWW-Authenticate' , f'Basic realm="{realm}"' ) if user is not None or password is not None : #self.engine.notification.message('authentication_warning',{'ip' : ip, 'username' : user, 'password' : password},[]) logger . warning ( f'Incorrect login detected using username \'{user}\' and password \'{password}\' from ip {ip}' ) return err if request . method . lower ( ) in [ 'get' , 'head' ] : self . __add_caching_headers ( response , request . fullpath ) if request . url . lower ( ) . endswith ( '.html' ) or '/' == request . fullpath : user , password = request . get_cookie ( 'auth' , secret = self . cookie_secret ) or ( None , None ) if check ( user , password ) : # Update the cookie timeout so that we are staying logged in as long as we are working on the interface response . set_cookie ( 'auth' , request . get_cookie ( 'auth' , secret = self . cookie_secret ) , secret = self . cookie_secret , * * { 'max_age' : 3600 , 'path' : '/' } ) elif request . method . lower ( ) in [ 'post' , 'put' , 'delete' ] : response . set_cookie ( 'no-cache' , '1' , secret = None , * * { 'max_age' : 90 , 'path' : '/' } ) response . set_header ( 'Cache-Control' , 'no-cache' ) return func ( * a , * * ka ) return wrapper return decorator