예제 #1
0
 def post(self):
     #如果username 和 password 合法,则访问数据库,如果appid下的username已经存在,则返回601
     if self.fd.haveUserName(self.appid, self.username):
         self.write(utils.json_failed(601))
     else:
         if not self.fd.saveUserInfo(self.appid, self.username, self.password):
             self.write(utils.json_failed(500))
         else:
             self.write(utils.json_success("注册成功"))
예제 #2
0
 def post(self):
     username = self.get_argument("username", None)
     if username:
         if self.fd.haveUserName(self.appid, username):
             self.write(utils.json_failed(601))
         else:
             self.write(utils.json_failed(602))
     else:
         self.write(utils.json_failed(401))
예제 #3
0
 def post(self):
     self.appid = self.get_argument("appid", None)
     self.text = self.get_argument("text", None)
     self.docid = self.get_argument("docid", None)
     self.tags = self.get_argument("tags", None)
     #检测text tags的长度
     if self.text and len(self.text) > const.MAX_TEXT_TAGS or self.tags and len(self.tags) > const.MAX_TEXT_TAGS:
         self.write(utils.json_failed(401))
     if not self.text or int(self.docid) < 1 or int(self.docid) > const.MAX_DOCID:
         self.write(utils.json_failed(401))
     else:
         self.response = yield self.index()
         self.write(self.response.body)
예제 #4
0
 def post(self):
     text = self.get_argument("text", None)
     mode = self.get_argument("mode", None)
     if not text or not mode:
         self.write(utils.json_failed(401))
     response = yield self.getCutFromGolang(text, mode)
     self.write(response.body)
     print self.method
     print self.body
     print response.body
     self.finish()
예제 #5
0
 def post(self):
     wd = self.get_argument("wd", None)
     sign_method = self.get_argument("sign_method", None)
     if not wd:
         raise ValueError(401)
     #拼装body
     data = {
         "appid": self.appid,
         "sign_method": sign_method,
         "text": wd,
         "docids": "0-" + str(self.novel.getNovelDocMaxId(self.appid)),
     }
     sign = utils.md5sign(appsecret, data)
     data["sign"] = sign
     self.body = urllib.urlencode(data)
     resp = yield self.client()
     result = []
     try:
         jsonret = json.loads(resp.body)
         if jsonret["code"] == 200:
             if len(jsonret["result"]["docs"]) != 0:
                 novellist = self.novel.getNovelListById(jsonret["result"]["docs"])
                 for v in novellist:
                     result.append({
                         'id': v['id'],
                         'picture': "/static/spider/" + v['picture'],
                         'introduction': "".join(v['introduction'].split()),
                         'title': v['title'],
                         'first': v['first'],
                         'second': v['second'],
                         'novelv': v['novelpv'],
                         'author': v['author'],
                     })
                 self.write(json_success(result))
             else:
                 self.write(json_success([]))
         else:
             self.write(json_failed(int(jsonret["code"])))
     except Exception as e:
         self.write(json_failed(500))
예제 #6
0
 def wrapper(*args, **kwargs):
     """
     验证用户名和密码的合法性
     :param args: self = args[0]
     :param kwargs:
     :return: 如果验证成功返回True 失败返回False
     """
     self = args[0]
     self.username = self.get_argument("username", None)
     self.password = self.get_argument("password", None)
     if not self.username or not self.password:
         self.write(utils.json_failed(401))
     else:
         return func(*args, **kwargs)
예제 #7
0
 def post(self):
     self.text = self.get_argument("text", None)
     self.docids = self.get_argument("docids", None)
     self.tags = self.get_argument("tags", None)
     self.timeout = self.get_argument("timeout", None)
     self.response = yield self.search()
     if self.response == 401:
         self.write(utils.json_failed(401))
     else:
         tmp = json.loads(self.response.body)["result"]
         r = {}
         r["tokens"] = tmp["Tokens"]
         r["docs"] = [utils.decodeDocid(int(self.appid), int(docid['DocId'])) for docid in tmp["Docs"]]
         r["timeout"] = tmp["Timeout"]
         self.write(utils.json_success(r))
     self.finish()