コード例 #1
0
 def get_current_user(self):
   # Check if cookie exists
   user_jwt = self.get_cookie("JWT")
   print(user_jwt)
   if user_jwt != None:
     # If it does, decode it
     decoded_user_jwt = jwt.decode(user_jwt, config["JWT_SECRET"], algorithms=["HS256"])
     # Return users info from Redis
     return json.loads(r.get("users:" + decoded_user_jwt["uuid"]))
   else:
     # If no cookie, no user exists
     return None
コード例 #2
0
 def post(self):
   event_data = json.loads(self.request.body)
   # Look up UUID of user based on request_id of webhook event
   user_uuid = r.get("requests:" + event_data["meta"]["resource_id"])
   # Get the websocket connection that corresponds to that user UUID
   user_socket = RequestStatusHandler.socket_connections[user_uuid]
   event_message = {"type": event_data["event_type"], "status": event_data["meta"]["status"]}
   print("event message:")
   print(event_messageh)
   # If status is "accepted" then obtain request details to send to client
   if event_data["meta"]["status"] == "accepted":
       user_access_token = json.loads(r.get("users:" + user_uuid))["tokens"]["access"]
       request_details = yield RideHandler.get_request(user_access_token, event_data["meta"]["resource_id"])
       print("Request details:")
       print(request_details)
       # Make sure status is still accepted since webhook event
       if (request_details["status"] == "accepted"):
           # Details will contain info about driver and vehicle and eta
           event_message["details"] = {
               # Driver schema 
               "driver": {
                   "name": request_details["driver"]["name"],
                   "rating": request_details["driver"]["rating"],
                   "phone_number": request_details["driver"]["phone_number"],
                   "picture_url": request_details["driver"]["picture_url"]
               },
               "eta": request_details["eta"],
               # Vehicle schema
               "vehicle": {
                   "make": request_details["vehicle"]["make"],
                   "model": request_details["vehicle"]["model"],
                   "license_plate": request_details["vehicle"]["license_plate"],
                   "picture_url": request_details["vehicle"]["picture_url"]
               }
           }
   user_socket.write_message(json.dumps(event_message))