Beispiel #1
0
  def get(self):
    access_key = self.request.get('access_key')
    result = self.request.get('result')
    if (not result) or (not access_key):
      logging.critical('tropo didnt provide access_key or result %s, %s' % (access_key, result))
      return self.response.out.write('no result or access_key')

    key_entry = ValidationRequest.get_by_key_name(access_key)
    if not key_entry:
      logging.critical('tropo requested with access_key %s but it does not exist' % access_key)
    key_entry.result = result
    key_entry.put()
    return self.response.out.write('')
Beispiel #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)