def remove_user_from_station(): d = request.get_json(force=True) uid = fireman.verify_uid(d.get('token', None)) maid = fireman.verify_maid(d.get('maid', None)) if not dbman.user_exists(uid): return err("INVALID_UID") if not dbman.station_exists(maid): return err("INVALID_MAID") dbman.remove_user_from_station(uid, maid) return suc()
def fetch_user_enrolls(): d = request.get_json(force=True) uid = fireman.verify_uid(d.get('token', None)) maid = fireman.verify_maid(d.get('maid', None)) if not dbman.user_exists(uid): return err("INVALID_UID") if not dbman.station_exists(maid): return err("INVALID_MAID") enrolls = dbman.get_enrolls_by_station(uid, maid) return suc({'enrolls': enrolls})
def override_user_enrolls(): d = request.get_json(force=True) uid = fireman.verify_uid(d.get('token', None)) if type(uid) is not str: return err("INVALID_UID") enrolls = d.get('data', None) if type(enrolls) is not str: return err("INVALID_DATA") dbman.override_user_enrolls(uid, enrolls) return suc()
def unlock_remote(): d = request.get_json(force=True) uid = fireman.verify_uid(d.get('token', None)) maid = fireman.verify_maid(d.get('maid', None)) if type(maid) is not str: return err("INVALID_MAID") if type(uid) is not str: return err("INVALID_UID") if not dbman.user_belongs_to_station(uid, maid): return err("UNAUTHORIZED") success = blaster.blast(maid, netman.SEQ_UNLOCK) return suc() if success else err("UNLOCK_FAILED")
def add_user_to_station(): d = request.get_json(force=True) uid = fireman.verify_uid(d.get('token', None)) maid = fireman.verify_maid(d.get('maid', None)) if not dbman.user_exists(uid): return err("INVALID_UID") if not dbman.station_exists(maid): return err("INVALID_MAID") dbman.add_user_to_station(uid, maid, -1) new_station = dbman.get_new_station(uid, maid) return suc(new_station)
def unlock_physical(): d = request.get_json(force=True) maid = fireman.verify_maid(d.get('maid', None)) uid = d.get('uid', None) if type(maid) is not str: return err("INVALID_MAID") if type(uid) is not str: return err("INVALID_UID") if not dbman.user_belongs_to_station(uid, maid): return err("UNAUTHORIZED") fireman.send_message_to_uid(uid, "UNLOCKED") return suc()
def upload_stream_image(): d = request.get_json(force=True) maid = fireman.verify_maid(d.get('maid', None)) if type(maid) is not str: return err("INVALID_MAID") print("Hue") png_base64 = d.get('png', None) if type(png_base64) is not str: return err("INVALID_PNG") print("HAA") pictures[maid] = {'picture': png_base64, 'received': time.time()} return suc()
def register_station(): d = request.get_json(force=True) maid = fireman.verify_maid(d.get('maid', None)) name = d.get('name', None) secret_code = d.get('secret_code', None) if type(maid) is not str: return err("INVALID_MAID") if type(name) is not str: return err("INVALID_NAME") if type(secret_code) is not str: return err("INVALID_SECRET_CODE") if maid not in blaster.stations: return err("SOCKET_DISCONNECTED") dbman.register_station(maid, name, secret_code) return suc()
def register_user(): d = request.get_json(force=True) uid = fireman.verify_uid(d.get('token', None)) if uid is None: return err("INVALID_TOKEN") fcm = d.get('fcm', None) name = d.get('name', None) dbman.register_user(uid, fcm, name) stations = dbman.get_user_stations(uid) return suc(stations)
def get_stream_image(): d = request.get_json(force=True) uid = fireman.verify_uid(d.get('token', None)) maid = fireman.verify_maid(d.get('maid', None)) if type(maid) is not str: return err("INVALID_MAID") if type(uid) is not str: return err("INVALID_UID") if not dbman.user_belongs_to_station(uid, maid): return err("USER_DOES_NOT_BELONG") blaster.blast(maid, netman.SEQ_STREAM) max_wait = 2 waited = 0 delay = 0.25 while waited < max_wait: now = time.time() if pictures.get(maid, None) is None or now - pictures[maid]['received'] > 15: time.sleep(delay) waited += delay else: return suc(pictures[maid]) return err("IMAGE_NOT_RECEIVED")
def fetch_user_stations(): d = request.get_json(force=True) uid = fireman.verify_uid(d.get('token', None)) if not dbman.user_exists(uid): return err("INVALID_UID") return suc(dbman.get_user_stations(uid))
def fetch_station_users(): d = request.get_json(force=True) maid = fireman.verify_maid(d.get('maid', None)) last_updated = d.get('last_updated', 0) if not dbman.station_exists(maid): return err("INVALID_MAID") return suc(dbman.get_station_users_after(maid, last_updated))