Ejemplo n.º 1
0
    def post(self):
        try:
            # 获取入参
            image_metas = self.request.files['image']
        except:
            # 获取入参失败时,抛出错误码及错误信息
            logger.info("UploadFileHandle: request argument incorrect")
            http_error_response(self, -1)
            return

        image_url = ""
        image_path_list = []
        if image_metas:
            # 获取当前的路径
            pwd = os.getcwd()
            save_image_path = os.path.join(pwd, "static/image/")
            logger.debug("UploadFileHandle: save image path: %s" % save_image_path)
            # 调用save_file方法将图片数据流保存在硬盘中
            file_name_list = save_files(image_metas, save_image_path)
            image_path_list = [SERVER_HEADER + "/static/image/" + i for i in file_name_list]
            ret_data = {"imageUrl": image_path_list}
            # 返回图片下载地址给客户端
            self.write(json.dumps({"data": {"msg": ret_data, "code": 0}}))
        else:
            # 如果图片为空,返回图片为空错误信息
            logger.info("UploadFileHandle: image stream is empty")
            http_error_response(self, -1)
Ejemplo n.º 2
0
 def write_error(self, status_code, **kwargs):
     error_trace_list = traceback.format_exception(*kwargs.get("exc_info"))
     if DEBUG:
         reason = ""
         if len(error_trace_list) > 0:
             reason = error_trace_list[-1]
         http_error_with_reason(self, status_code, reason)
     else:
         http_error_response(self, status_code)
Ejemplo n.º 3
0
 def post(self):
     try:
         phone = self.get_argument("phone")
         password = self.get_argument("password")
     except KeyError:
         # 获取入参失败时,抛出错误码及错误信息
         logger.info("demo_post_form: request argument incorrect")
         http_error_response(self, 1001)
         return
     logger.debug("demo_post_form:success")
     http_success_response(self, {
         "phone": phone,
         "password": password
     }, "demo_post_form成功")
Ejemplo n.º 4
0
 def get(self):
     try:
         phone = self.get_argument("phone")
         password = self.get_argument("password")
     except KeyError:
         # 获取入参失败时,抛出错误码及错误信息
         logger.info("RegistHandle: request argument incorrect")
         http_error_response(self, 1001)
         return
     logger.debug("RegistHandle: regist successfully")
     http_success_response(self, {
         "phone": phone,
         "password": password
     }, "注册成功")
Ejemplo n.º 5
0
    def get(self):
        self.set_header("Content-Type", "text/html; charset=UTF-8")
        try:
            # 获取入参
            phone = self.get_argument("phone")
            password = self.get_argument("password")
        except:
            # 获取入参失败时,抛出错误码及错误信息
            logger.info("LoginHandle: request argument incorrect")
            http_error_response(self, 1001)
            return

        # 从数据库 Users 表查找入参中的 phone 是否存在
        logger.debug("LoginHandle: get user login: %s" % phone)
        self.render("index.html")
Ejemplo n.º 6
0
 def post(self):
     self.set_header("Content-Type", "application/json;charset=UTF-8")
     try:
         # 获取入参
         args = json_decode(self.request.body)
         phone = args['phone']
         password = args['password']
         verify_code = args['code']
     except:
         # 获取入参失败时,抛出错误码及错误信息
         logger.info("RegistHandle: request argument incorrect")
         http_error_response(self, 1001)
         return
     logger.debug("RegistHandle: regist successfully")
     http_success_response(self, "", "注册成功")
Ejemplo n.º 7
0
 def post(self):
     try:
         # 获取入参
         args = json_decode(self.request.body)
         phone = args['phone']
         password = args['password']
     except KeyError:
         # 获取入参失败时,抛出错误码及错误信息
         logger.info("RegistHandle: request argument incorrect")
         http_error_response(self, 1001)
         return
     logger.debug("RegistHandle: regist successfully")
     http_success_response(self, {
         "phone": phone,
         "password": password
     }, "postJsonBody发送成功")