예제 #1
0
 def get(self):
   import time
   t2 = time.time()
   do = self.request.get('do')
   if (do == 'delete_requests'):
     db.delete(ValidationRequest.all(keys_only=True).fetch(200))
     return self.redirect('/validator')
   
   elif do == 'delete_quotas':
     db.delete(DemoClient.all(keys_only=True).fetch(200))
     return self.redirect('/validator')
   
   service_users = ServiceUser.all().fetch(100)
   validation_requests = ValidationRequest.all().fetch(100)
   t = time.time()
   for service_user in service_users:
     service_user.api_key = service_user.key().name()
   
   for validation_request in validation_requests:
     validation_request.access_key = validation_request.key().name()  
   now = time.time()
   logging.debug('LOG1%f' %(now - t))
   logging.debug('LOG2%f' %(now - t2))
   context = {
     'service_users':service_users,
     'validation_requests':validation_requests,
   }
   return self.render_response('validator.html', context)
예제 #2
0
 def post(self):
   step = self.request.get('step',"")
   phone = self.request.get('phone',"")
   self_recorded = self.request.get('self_recorded',"")
   if (not phone) and (not step):
     return self.response.out.write('no phone given')
   
   if (step):
     access_key = self.request.get('access_key')
     secret = self.request.get('secret')
     ds_entry = ValidationRequest.get_by_key_name(access_key)
     if (ds_entry.secret == int(secret)):
       return self.render_response('validation-demo-right.html')
     else:
       return self.render_response('validation-demo-wrong.html')
   else:
     ip = self.request.remote_addr
     ds_existing = DemoClient.get_by_key_name(ip)
     if not ds_existing:
       DemoClient(key_name=ip, times=1).put(rpc=db.create_rpc())
     else:
       if (ds_existing.times > 4):
         return self.redirect('/validator/demo?step=fail')
       ds_existing.times = ds_existing.times + 1
       ds_existing.put(rpc=db.create_rpc())
     target = 'tel:'+phone
     secret = tropo.generate_secret()
     access_key = tropo.generate_key()
     call_context = {
       'to':target,
       'intro':'This is our service demo! Your secret code is :',
       'secret':secret,
       'access_key':access_key,
       'self_recorded':self_recorded,
       'callback_host':CALLBACK_HOST
     }
     fetch_rpc = tropo.tropo_run_script(call_context, async=True)
     rpc = db.create_rpc()
     validation_entry = ValidationRequest(
           key_name = access_key,
           target = target,
           api_key = tropo.DEMO_API_KEY,
           secret = int(secret)).put(rpc=rpc)
     rpc.wait()
     fetch_rpc.wait()
     
   return self.redirect('/validator/demo?step=2&access_key='+access_key)