Esempio n. 1
0
 def get_delete(self, x):
     docu_id = x.docu_id
     try:
         xss_db.delete('docu', where='id=$docu_id', vars=locals())
     except Exception as error:
         return utils.json_response(197, str(error))
     return utils.json_response(196)
Esempio n. 2
0
 def post_account_setting(self, x):
     keys = x.keys()
     if "email" in keys:
         email = x.email
         if email.strip():
             userid = web.ctx.session.userid
             try:
                 xss_db.update("user", where="id=$userid", name=email, email=email, vars=locals())
             except Exception as error:
                 return utils.json_response(205, str(error))
             web.ctx.session.user = email
             web.ctx.session.email = email
     if "oldpass" in keys and "newpass" in keys and "confirmpass" in keys:
         passwd = (x.oldpass).strip()
         newpasswd = (x.newpass).strip()
         confirmpasswd = (x.confirmpass).strip()
         if passwd and newpasswd and confirmpasswd:
             pwhash = hashlib.md5(passwd).hexdigest()
             result = xss_db.query(
                 "select count(*) as count from user where id=$userid and pwhash=$pwhash",
                 vars={"userid": web.ctx.session.userid, "pwhash": pwhash},
             )
             if not result[0].count == 1:
                 error = "passwd is error"
                 return utils.json_response(205, str(error))
             web.ctx.session.user = email
             if not newpasswd == confirmpasswd:
                 error = u"两次输入的密码不相同"
                 return utils.json_response(205, str(error))
             web.ctx.session.user = email
             try:
                 xss_db.update("user", where="id=$userid", pwhash=pwhash, vars=locals())
             except Exception as error:
                 return utils.json_response(205, str(error))
     return utils.json_response(204)
Esempio n. 3
0
 def post_contact_us(self, x):
     feedback = x.feedback
     print 'contact_us'
     try:
         xss_db.insert('feedback', content=feedback)
     except Exception as error:
         return utils.json_response(207, str(error))
     return utils.json_response(206)
Esempio n. 4
0
 def fetch_job(self, x, method):
     message = "get %s, do not support"%(method)
     hander = x['hander']
     if not hander.startswith('%s_'%(method)):
         return utils.json_response(1, message)
     hander = getattr(self, hander)
     if not hander:
         return utils.json_response(1, message)
     return hander(x)
Esempio n. 5
0
 def post_email_settings(self, x):
     past = (x.past).strip()
     sendtime = x.sendtime
     userid = web.ctx.session.userid
     try:
         xss_db.update("user", where="id=$userid", sendtime=sendtime, past=past, vars=locals())
     except Exception as error:
         return utils.json_response(107, str(error))
     return utils.json_response(108)
Esempio n. 6
0
 def POST(self):
     x = web.input()
     print x
     hander = x['hander']
     if not hander.startswith('post_'):
         return utils.json_response(1, 'do not support this post hander')
     hander = getattr(self, hander)
     if not hander:
         message = u'do not support this hander: %s'%(hander)
         return utils.json_response(1, message)
     return hander(x)
Esempio n. 7
0
 def POST(self):
     x = web.input()
     print x
     hander = x["hander"]
     if not hander.startswith("post_"):
         return utils.json_response(1, "this post hander is not support")
     hander = getattr(self, hander)
     if not hander:
         message = u"do not support this hander: %s" % (hander)
         return utils.json_response(1, message)
     return hander(x)
Esempio n. 8
0
 def post_edit(self, x):
     title = None if 'title' not in x.keys() else x.title
     content = None if 'content' not in x.keys() else x.content
     docu_id = x.docu_id
     source = 'web'
     try:
         if title:
             xss_db.update('docu', where='id=$docu_id', title=title, vars=locals())
         if content:
             xss_db.update('docu', where='id=$docu_id', content=content, vars=locals())
     except Exception as error:
         return utils.json_response(199, str(error))
     return utils.json_response(198)
Esempio n. 9
0
 def post_email_frequency(self, x):
     print x
     userid = web.ctx.session.userid
     if x["sendemails"] == u"2":
         if not "days[]" in x.keys():
             return utils.json_response(203, "i need a this key :days[]")
         try:
             xss_db.update(
                 "user", where="id=$userid", frequency=x["sendemails"], weekly=str(x["days[]"]), vars=locals()
             )
         except Exception as error:
             return utils.json_response(203, str(error))
     elif x["sendemails"] == u"1":
         try:
             xss_db.update("user", where="id=$userid", frequency=x["sendemails"], vars=locals())
         except Exception as error:
             return utils.json_response(203, str(error))
     elif x["sendemails"] == u"0":
         try:
             xss_db.update("user", where="id=$userid", frequency=x["sendemails"], vars=locals())
         except Exception as error:
             return utils.json_response(203, str(error))
         try:
             xss_db.insert("feedback", userid=userid, content=x["neverfeedback"])
         except Exception as error:
             return utils.json_response(203, str(error))
     else:
         error = "sendmails 不是预期的的 0,1,2"
         return utils.json_response(203, str(error))
     return utils.json_response(202)
Esempio n. 10
0
 def post_add(self, x):
     title = None if 'title' not in x.keys() else x.title
     content = x.content
     atime = x.date
     userid = web.ctx.session.userid
     source = 'web'
     def format_atime(atime):
         a = [str(i) for i in atime.split('/')]
         if len(a[0]) == 1: a[0] = '0'+a[0]
         if len(a[1]) == 1: a[1] = '0'+a[1]
         b = ':'.join(a[::-1])
         return b + ' 12:00:00'
     atime = format_atime(atime)
     if not title:
         title = atime
     if not content or not atime:
         return utils.json_response(201, 'content or date is null')
     try:
         xss_db.insert('docu', title=title, content=content, userid=userid, source=source, atime=atime)
     except Exception as error:
         return utils.json_response(201, str(error))
     return utils.json_response(200)
Esempio n. 11
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)
Esempio n. 12
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")
Esempio n. 13
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)