def connect(): #process users credentials here. db = DBHelper(True) #close the connection in this function. username = flask_request.form['username_field'] password = flask_request.form['password_field'] authSuccess = db.authenticate([username, password]) if (authSuccess): #make the connection to compess here. hub_id = db.getHubIdByUsername(username) net_id = db.getNetIdByUsername(username) acu_id = db.getACUByUsername(username) access_key = db.getAccessKeyByUsername(username) comms.registerUser(username, password, net_id, hub_id, acu_id, access_key) #comms.web_factory.rec.is_registering = True resp = make_response(render_template('active.html', user=username)) return resp else: return render_template( 'index.html', message="Failed to authenticate. Please try again. ") db.disconnect()
def onMessage(self, data, isBinary): """ Description: Decodes the image sent from the camera """ #STEP 1: Load in, convert, and decompress frame for use frame = ujson.loads(data.decode("utf8")) frame = np.asarray(frame, np.uint8) frame = cv2.imdecode(frame, cv2.IMREAD_COLOR) #post users client name here. #frame = message if (self.factory.bridge.user is not None): print(self.factory.bridge.user) frame, username, gesture = self.factory.rec.processFrame( frame, self.factory.bridge.user) if (gesture != '0'): #gesture is '0' by default db = DBHelper(True) gest_func = db.getGestureFunction(username, "gest_" + str(gesture)) acu = db.getACUByUsername(username) tag = acu + ",," + str(gest_func) if gest_func != None: self.factory.bridge.sendTag(tag) if (self.factory.rec.is_registering == False and self.factory.rec.reg_complete == True): self.factory.bridge.web_factory.connections["client1"].sendMessage( "registration".encode("UTF8")) frame = cv2.UMat(frame) frame = cv2.imencode('.jpg', frame, [cv2.IMWRITE_JPEG_QUALITY, 20])[1] frame = base64.b64encode(frame) #send to web factory self.factory.bridge.web_factory.post(self.factory.bridge.user, frame)