def main(): """ Register a new User or Authenticates the already registered User to send message """ try: if auth.check_existed(CURRENT_USER): password = getpass(f"User {CURRENT_USER} found\nEnter password: "******"Welcome {CURRENT_USER} to tmessage!\nPlease register...") displayed_name = input("Enter your name used for display: ") password = getpass("Enter password: "******"Re-enter password: "******"Passwords do not match, please try again...") password = getpass("Enter password: "******"Re-enter password: "******"User Authorized") user_name = payload["user_name"] displayed_name = payload["displayed_name"] MQTT_CLIENT.on_message = on_message MQTT_CLIENT.connect(BROKER_ENDPOINT, BROKER_PORT) MQTT_CLIENT.subscribe(MQTT_TOPIC) MQTT_CLIENT.loop_start() while True: raw_msg = str(input(Back.RESET + Fore.RESET)) formatted_msg = get_formatted_message(raw_msg) pub_msg = f"[{user_name}] {displayed_name}: {formatted_msg}" if raw_msg != "": MQTT_CLIENT.publish(MQTT_TOPIC, pub_msg) if IS_STORE: database(CURRENT_USER, formatted_msg, new) else: print(Back.WHITE + Fore.RED + "Can't send empty message", end="\n") except KeyboardInterrupt: # pylint: disable=pointless-statement MQTT_CLIENT.disconnect() Style.RESET_ALL deinit() print("\nGoodbye!") except ConnectionRefusedError: # pylint: disable=pointless-statement Style.RESET_ALL deinit() print("\nCan't connect please check your network connection") except Exception as err: # pylint: disable=broad-except # pylint: disable=pointless-statement Style.RESET_ALL deinit() print(f"\n{err}")
def main(): """ Register a new User or Authenticates the already registered User to send message """ try: if auth.check_existed(CURRENT_USER): password = input(f'User {CURRENT_USER} found\nEnter password: '******'Welcome {CURRENT_USER} to tmessage!\nPlease register...') displayed_name = input(f'Enter your name used for display: ') password = input(f'Enter password: '******'Re-enter password: '******'Passwords do not match, please try again...') password = input(f'Enter password: '******'Re-enter password: '******'User Authorized') user_name = payload["user_name"] displayed_name = payload["displayed_name"] MQTT_CLIENT.on_message = on_message MQTT_CLIENT.connect(BROKER_ENDPOINT, BROKER_PORT) MQTT_CLIENT.subscribe(MQTT_TOPIC) MQTT_CLIENT.loop_start() while True: raw_msg = str(input(Back.RESET + Fore.RESET)) pub_msg = f'[{user_name}] {displayed_name}: {raw_msg}' if raw_msg != '': MQTT_CLIENT.publish(MQTT_TOPIC, pub_msg) if IS_STORE: store_messages(CURRENT_USER, raw_msg) else: print(Back.WHITE + Fore.RED + "Can't send empty message", end='\n') except KeyboardInterrupt: # pylint: disable=pointless-statement MQTT_CLIENT.disconnect() Style.RESET_ALL deinit() print('\nGoodbye!') except ConnectionRefusedError: # pylint: disable=pointless-statement Style.RESET_ALL deinit() print("\nCan't connect please check your network connection") except Exception as err: # pylint: disable=broad-except # pylint: disable=pointless-statement Style.RESET_ALL deinit() print(f'\n{err}')