예제 #1
0
from google.appengine.ext import db
import keymodel,cmdmodel
import keyverify
class MainPage(webapp2.RequestHandler):
    def post(self):
        self.response.headers['Content-Type'] = 'application/json'
        rescmd = []
        resmsg = {'err':'error','response':rescmd}
        try:
            enctext=eval(self.request.get('signature'))
            encinfo=eval(self.request.get('userinfo'))
        except Exception,data:
            logging.error(data)
            resmsg['err'] = data
        else:
            user = keyverify.verifyKey(enctext, encinfo)
            if user:
                resmsg['err'] = 'ok'
                cmd = db.GqlQuery("SELECT * FROM CmdInfos WHERE user = :1 ORDER BY mtime",user)
                for c in cmd:
                    rescmd.append({'cmd':c.cmd, 
                        'mtime':(c.mtime + datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S"),
                        'etime':(c.etime + datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S"),
                        'info':c.info,
                        'new':c.new,
                        'key':str(c.key())})
                    if c.new:
                        c.new = False
                        c.etime = datetime.datetime.utcnow()
                        c.put()
                resmsg['response'] = rescmd        
예제 #2
0
import keyverify
class MainPage(webapp2.RequestHandler):
    def post(self):
        self.response.headers['Content-Type'] = 'application/json'
        resmsg = {'err':'error'}
        try:
            enctext=eval(self.request.get('signature'))
            encinfo=eval(self.request.get('userinfo'))
            strkey = self.request.get('key')
            logging.debug(strkey)
            cmdinfo = self.request.get('cmdinfo')
        except Exception,data:
            logging.error(data)
            resmsg['err'] = data
        else:
            if keyverify.verifyKey(enctext, encinfo):
                k = db.Key(encoded=strkey)
                cmd = db.get(k)
                if cmd:
                    cmd.info = cmdinfo
                    cmd.put()
                    resmsg['err'] = 'ok'
                else:
                    logging.warn('cmd none')
            else:
                logging.error('verifyKey error')
        self.response.write(json.dumps(resmsg))    

app=webapp2.WSGIApplication([('/updateinfo',MainPage)],
                            debug=True)