예제 #1
0
 async def get_access_token(self, customer_id):
     logger.debug("get nx_app_user_token: { customer_id: %s }" %
                  customer_id)
     doc = await self.collection.find_one({'customer_id': customer_id})
     logger.debug("return document: " + str(doc))
     if doc:
         return doc['access_token']
     return None
예제 #2
0
 async def get_token(self, data=None):
     logger.debug("get nx_app_user_token: %s" % data)
     data['status'] = 0
     if data:
         doc = self.collection.find(app_token(data))
     else:
         doc = self.collection.find()
     docs = await doc.to_list(None)
     logger.debug("return document:" + str(docs))
     return docs
예제 #3
0
 def insert(self, data=None):
     """
     插入
     :param data:
     :return:
     """
     logger.debug("insert nx_app_user_token: %s" % data)
     result = self.collection.insert_one(app_token(data))
     logger.debug('result %s' % repr(result.inserted_id))
     return result
예제 #4
0
 async def async_get_token_by_cid_aid(self, app_id, customer_id):
     logger.debug(
         "get nx_app_user_token: { customer_id: %s, app_id: %s, status: 0 }"
         % (customer_id, app_id))
     doc = await self.collection.find_one({
         'app_id': app_id,
         'customer_id': customer_id,
         'status': 0
     })
     logger.debug("return document: " + str(doc))
     return doc
예제 #5
0
 def update(self, app_id, customer_id, data=None):
     document = self.collection.update_one(
         {
             'app_id': app_id,
             'customer_id': customer_id,
             'status': 0
         }, {'$set': app_token(data)})
     logger.debug(
         "update nx_app_user_token: app_id %s, customer %s -> %s, ret: %s" %
         (app_id, customer_id, data, document))
     return True
예제 #6
0
    def get_token_by_cid_aid(self, app_id, customer_id):
        logger.debug("get nx_app_user_token: { customer_id: %s, app_id: %s }" %
                     (customer_id, app_id))
        doc = self.collection.find_one({
            'app_id': app_id,
            'customer_id': customer_id,
            'status': 0
        })

        logger.debug("return document: " + str(doc))
        print(dict(doc))
        return dict(str(doc))
예제 #7
0
    def _delist_arguments(self, arguments):
        logger.debug(f"before_args:{arguments}")

        # for arg, value in arguments.items():
        #     logger.debug(f'{type(value)}')
        #     if isinstance(value, list):
        #         arguments[arg] = [v.decode("utf-8").strip() if isinstance(v, bytes) else v.strip() for v in value]

        def decode_(v):
            return self.decode_argument(v).strip()

        arguments = {k: list(map(decode_, v)) for k, v in arguments.items()}

        logger.debug(f"after_args:{arguments}")
        return arguments
예제 #8
0
    def prepare(self):
        """Called at the beginning of a request before  `get`/`post`/etc.

        Override this method to perform common initialization regardless
        of the request method.

        Asynchronous support: Decorate this method with `.gen.coroutine`
        or use ``async def`` to make it asynchronous (the
        `asynchronous` decorator cannot be used on `prepare`).
        If this method returns a `.Future` execution will not proceed
        until the `.Future` is done.

        .. version added:: 3.1
           Asynchronous support.
        """
        if self.request.body and self.request.headers.get(
                "Content-Type", "").startswith("application/json"):
            try:
                logger.debug(f"json_args:{self.request.body}")
                self.json_args = json_decode(self.request.body)
                self.request.arguments.update(self.json_args)
            except ValueError:
                self.write_error(
                    405, msg='Unable to parse JSON.')  # Bad RequestHandler
예제 #9
0
    async def _dispatch(self, method):
        kwargs = {}
        # Sanitize argument lists:
        if self.request.arguments:
            kwargs = self._delist_arguments(self.request.arguments)
        path = self.request.uri.split('?')[0]
        path_segs = path.split('/')
        if len(path_segs) < 2:
            logger.debug("len(path_segs) < 2")
            raise HTTPError(**HTTP_ERRORS['status_404'])

        method = f"{method}_{path_segs[-1]}"
        logger.debug("path: %s, method: %s" % (path, method))

        func = getattr(self, method, None)
        if callable(func):
            return await func(**kwargs)
        else:
            logger.debug("func no callable")
            if self.is_exist_supported_method(path_segs[-1]):
                raise HTTPError(**HTTP_ERRORS['status_405'])

            raise HTTPError(**HTTP_ERRORS['status_404'])
예제 #10
0
 async def delete(self):
     logger.debug("route path: BaseHandler -> delete")
     return await self._dispatch('delete')
예제 #11
0
 async def put(self):
     logger.debug("route path: BaseHandler -> put")
     return await self._dispatch('put')
예제 #12
0
 async def get(self):
     logger.debug("route path: BaseHandler -> get")
     return await self._dispatch('get')