Ejemplo n.º 1
0
    def _dispatch(self):
        """
		Load up the requested URL if it matches one of our own methods.
		Skip methods that start with an underscore (_).
		"""
        args = {}
        id, self.id = create_id()
        self.logger = logging.LoggerAdapter(parent_logger, {
            'id': id,
            'ip': self.client_ip
        })
        # Sanitize argument lists:
        if self.request.arguments:
            args = delist_arguments(self.request.arguments)
        # Special index method handler:
        path = self.request.uri.split('?')[0]
        method = path.split('/')[-1]
        if not method.startswith('_'):
            func = getattr(self, method, None)
            if func:
                try:
                    result = func(**args)
                    if isinstance(result, GeneratorType):
                        result = yield from result
                    if not isinstance(result, str):
                        result = json.dumps(result)
                    self.finish(result)
                except ValidationError as e:
                    self.set_status(409)
                    self.finish(str(e.message))
            else:
                raise tornado.web.HTTPError(404)
        else:
            raise tornado.web.HTTPError(404)
Ejemplo n.º 2
0
	def wrapper(self, *a, **ka):
		self.user_id = get_user_id(self.request)
		self.logger = logging.LoggerAdapter(parent_logger, {
			'id': create_id(self.user_id, self.id),
			'ip': self.client_ip
		})
		if self.user_id is None:
			raise tornado.web.HTTPError(403, 'Missing or expired session_id header')
		return func(self, *a, **ka)
Ejemplo n.º 3
0
    def generate_self_id(self):
        """
		When user opens new tab in browser wsHandler.wsConnectionId stores Id of current ws
		So if ws loses a connection it still can reconnect with same id,
		and TornadoHandler can restore webrtc_connections to previous state
		"""
        conn_arg = self.get_argument('id', None)
        self.id, random = create_id(self.user_id, conn_arg)
        self.restored_connection = random == conn_arg
        self.restored_connection = False
        self.save_ip()
Ejemplo n.º 4
0
	def wrapper(self, *a, **ka):
		session_id = self.request.headers.get('session_id')
		if session_id is None:
			raise tornado.web.HTTPError(403, 'session_id header is missing')
		self.user_id = int(sync_redis.hget('sessions', session_id))
		self.logger = logging.LoggerAdapter(parent_logger, {
			'id': create_id(self.user_id, self.id),
			'ip': self.client_ip
		})
		if self.user_id is None:
			raise tornado.web.HTTPError(403, 'session {} is invalid'.format(session_id))
		return func(self, *a, **ka)