Example #1
0
 def get_accountinfo(self, x):
     userid = web.ctx.session.userid
     print userid
     myvar = {"userid": userid}
     try:
         t = xss_db.select("user", myvar, where="id=$userid")
     except Exception as error:
         return utils.json_response(102, str(error))
     print t
     j = {}
     for i in t:
         for key in i.keys():
             j[key] = i[key]
     return json.dumps(j)
Example #2
0
 def get_alldocus(self, x):
     userid = web.ctx.session.userid if "userid" not in x.keys() else x.userid
     d = {}
     myvar = {"userid": userid}
     t = xss_db.select("docu", myvar, where="userid=$userid")
     print t
     docus = []
     for i in t:
         j = {}
         for key in i.keys():
             j[key] = i[key]
         docus.append(j)
     d["docus"] = docus
     return json.dumps(d)
Example #3
0
 def post_regiest(self, x):
     passwd = x.passwd
     email = x.email
     print "in regiest", email, passwd
     pwhash = hashlib.md5(passwd).hexdigest()
     try:
         xss_db.insert("user", name=email, email=email, pwhash=pwhash)
     except Exception as error:
         return utils.json_response(106, str(error))
     myvar = {"email": email, "pwhash": pwhash}
     t = xss_db.select("user", myvar, what="id", where="email=$email and pwhash=$pwhash")
     userid = t[0]["id"]
     web.ctx.session.user = email
     web.ctx.session.email = email
     web.ctx.session.userid = userid
     raise web.seeother("/today")
Example #4
0
 def get_docus(self, x):
     """可接受的参数为 storage {"userid":"", "offset":1, "limit":1} """
     print x
     userid = web.ctx.session.userid if "userid" not in x.keys() else x.userid
     offset = 0 if "offset" not in x.keys() else x.offset
     limit = 1 if "limit" not in x.keys() else x.limit
     d = {}
     myvar = {"userid": userid}
     t = xss_db.select("docu", myvar, where="userid=$userid", limit=limit, offset=offset)
     print t
     docus = []
     for i in t:
         j = {}
         for key in i.keys():
             j[key] = i[key]
         docus.append(j)
     d["docus"] = docus
     return json.dumps(d)
Example #5
0
 def post_login(self, x):
     passwd = x.passwd
     email = x.email
     pwhash = hashlib.md5(passwd).hexdigest()
     myvar = {"email": email, "pwhash": pwhash}
     t = xss_db.select("user", myvar, where="email=$email and pwhash=$pwhash")
     print "login", t
     is_login = False
     for i in t:
         print i
         web.ctx.session.user = i["name"]
         web.ctx.session.userid = i["id"]
         web.ctx.session.email = email
         is_login = True
     if is_login:
         raise web.seeother("/today")
     else:
         return utils.json_response(102)
Example #6
0
 def get_export(self, x):
     userid = web.ctx.session.userid
     d_num = time.strftime("%j", time.localtime())
     export_path = "static/export/%s/%s.txt" % (str(d_num), str(userid))
     if not os.path.isdir(os.path.dirname(export_path)):
         os.makedirs(os.path.dirname(export_path))
     myvar = {"userid": userid}
     t = xss_db.select("docu", myvar, where="userid=$userid")
     print t
     with open(export_path, "w") as f:
         for i in t:
             print i
             f.write(i["atime"] + "\n")
             f.write(i["title"] + "\n")
             f.write(i["content"] + "\n")
             f.write("\n")
     save_name = "walkbox_" + time.strftime("%Y%m%d", time.localtime()) + ".txt"
     web.header("Content-Type", "txt/plain")
     web.header("Location", export_path)
     web.header("Content-Disposition", "attachment;filename=%s" % (save_name))
     print "here export"
     return open("%s" % export_path, "r").read()