def add_tag_after_command(user: User, tag_uuid): if tag_uuid is not None: if User.User({"tag_uuid": tag_uuid}).user_uuid != "": mf.add_tag(user, tag_uuid) return "User added successfully" else: return "User already exists!"
def checkout(data): mm_username = request.form["user_name"] user = User.User({"mm_username": mm_username}) lab = mongo_labs.find_one({"_id": user.lab_uuid}) if user.lab_uuid != "0": user.checkout() text = "The user {} was successfully checked out!".format( user.mm_username) payload = response_format(text, user.first_name) else: payload = response_format("You are not checked in any lab!", user.first_name) return payload
def status(data): for lab in mongo_labs.find(): # mongo_labs.update({'_id': 'lab1'}, {'$inc': {'user_count': 1}}) users = lab["users"] if len(users) == 1: message = f"There is 1 user in {lab['desc']}\n\n" else: message = f"There are {len(users)} users in {lab['desc']}\n\n" for user in users: # print("user:"******"_id": user}) user = User.User({"_id": user}) message += f"{user.first_name} {user.last_name}\n" return response_format(message, len(users))
def handle_mqtt_message(client, userdata, message): payload = json.loads(message.payload.decode()) user = User.User(payload) device_uuid = payload["device_uuid"] lab = mongo_functions.get_lab_by_device(device_uuid) lab_uuid = lab.get("_id") # Check if there are waiting tasks to be performed e.g. a tag assignment if queue: # Call the corresponding function func, data = queue.pop(0) res = func(user=data, tag_uuid=payload["tag_uuid"][0]) print(res) else: # If there are no tasks in queue if payload["tag_uuid"][0] == "C9D3A847": mongo_functions.remove_all_from_lab() if user.user_uuid != "": if user.lab_uuid == "0" or user.lab_uuid == "": user.checkin(lab_uuid) else: user.checkout() response = { "lab_uuid": user.lab_uuid, "top_line": "Welcome" if user.lab_uuid != "0" else "Goodbye", "bottom_line": "{} {}.".format(user.last_name, user.first_name[0]), } mqtt.publish("laboratorium/lab1/auth/response", json.dumps(response)) else: response = { "lab_uuid": user.lab_uuid, "top_line": "Error", "bottom_line": "Unknown User", } mqtt.publish("laboratorium/lab1/auth/response", json.dumps(response))
def add_tag(data): data = data.split(" ", 1) # ! Care when using in async if hook_user_is_admin(): text = "You are not allowed to excecute this command." elif len(data) == 1: username = data[0] user = User.User({"mm_username": username}) print(username, user.__dict__) if user.user_uuid != "": # Add the new assignment task in queue queue.append((events.add_tag_after_command, user)) text = "Waiting for tag scan..." else: text = "User does not exist." else: text = "Wrong request format." return response_format(text, text)
def hook_user_is_admin(): hook_user = User.User({"mm_username": request.form.get("user_name")}) return hook_user.administrator
def get_all_users(): users = [] for user in mongo_users.find(): users.append(User.User(user)) return users