Update client.py
This commit is contained in:
22
client.py
22
client.py
@@ -65,8 +65,8 @@ def login():
|
|||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
except:
|
except:
|
||||||
data = {}
|
data = {}
|
||||||
user = input(wit + "Gebruikersnaam: " + reset)
|
user = input(wit + "user: " + reset)
|
||||||
password = getpass.getpass(wit + "Wachtwoord: " + reset)
|
password = getpass.getpass(wit + "password: " + reset)
|
||||||
password_hash = hashlib.sha256(password.encode("utf-8")).hexdigest()
|
password_hash = hashlib.sha256(password.encode("utf-8")).hexdigest()
|
||||||
if user in data and data[user] == password_hash:
|
if user in data and data[user] == password_hash:
|
||||||
return user
|
return user
|
||||||
@@ -100,11 +100,11 @@ while not current_user:
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
print( groen + "========================================")
|
print( groen + "========================================")
|
||||||
print("Welkom bij De Terminal Chat")
|
print(" Welcome to the Terminal Chat")
|
||||||
print("========================================" + reset)
|
print("========================================" + reset)
|
||||||
print()
|
print()
|
||||||
print_white("1. inloggen")
|
print_white("1. Login")
|
||||||
print_white("2. nieuw account")
|
print_white("2. Sign up")
|
||||||
print()
|
print()
|
||||||
keuze = input(wit + " > " + reset)
|
keuze = input(wit + " > " + reset)
|
||||||
print()
|
print()
|
||||||
@@ -170,7 +170,7 @@ def chat_session(chatkeuze):
|
|||||||
if isinstance(decoded, dict) and decoded.get("type") == "users_list":
|
if isinstance(decoded, dict) and decoded.get("type") == "users_list":
|
||||||
users = decoded.get("users", [])
|
users = decoded.get("users", [])
|
||||||
print("\nUsers:", ", ".join(users))
|
print("\nUsers:", ", ".join(users))
|
||||||
print(wit + "Typ je bericht: " + reset, end="", flush=True)
|
print(wit + "> " + reset, end="", flush=True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# normale chat update
|
# normale chat update
|
||||||
@@ -180,7 +180,7 @@ def chat_session(chatkeuze):
|
|||||||
chat_users = decoded[chatkeuze].get("users", [])
|
chat_users = decoded[chatkeuze].get("users", [])
|
||||||
|
|
||||||
draw_chat_window(chat_messages, chatkeuze)
|
draw_chat_window(chat_messages, chatkeuze)
|
||||||
print(wit + "Typ je bericht: " + reset, end="", flush=True)
|
print(wit + "> " + reset, end="", flush=True)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
break
|
break
|
||||||
@@ -189,7 +189,7 @@ def chat_session(chatkeuze):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
draw_chat_window(chat_messages, chatkeuze)
|
draw_chat_window(chat_messages, chatkeuze)
|
||||||
bericht = input(wit + "Typ je bericht: " + reset)
|
bericht = input(wit + "> " + reset)
|
||||||
|
|
||||||
if bericht.lower() == "/quit":
|
if bericht.lower() == "/quit":
|
||||||
exit()
|
exit()
|
||||||
@@ -229,14 +229,14 @@ def chat_session(chatkeuze):
|
|||||||
}).encode("utf-8"))
|
}).encode("utf-8"))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print_white(" --- Beschikbare chats: --- ")
|
print_white(" --- Available chats: --- ")
|
||||||
for i, chat in enumerate(chat_names, start=1):
|
for i, chat in enumerate(chat_names, start=1):
|
||||||
print_white(f"{i}. {chat}")
|
print_white(f"{i}. {chat}")
|
||||||
print_white(f"{len(chat_names)+1}. Nieuwe chat aanmaken")
|
print_white(f"{len(chat_names)+1}. New chat")
|
||||||
keuze = input(wit + " > " + reset)
|
keuze = input(wit + " > " + reset)
|
||||||
|
|
||||||
if keuze.isdigit() and int(keuze) == len(chat_names)+1:
|
if keuze.isdigit() and int(keuze) == len(chat_names)+1:
|
||||||
nieuwe_chat = input("Naam van nieuwe chat: ")
|
nieuwe_chat = input("Name of new chat: ")
|
||||||
s.sendall(json.dumps({"action": "new_chat", "chat_name": nieuwe_chat}).encode("utf-8"))
|
s.sendall(json.dumps({"action": "new_chat", "chat_name": nieuwe_chat}).encode("utf-8"))
|
||||||
data = s.recv(4096)
|
data = s.recv(4096)
|
||||||
chat_data = json.loads(data.decode("utf-8"))
|
chat_data = json.loads(data.decode("utf-8"))
|
||||||
|
|||||||
Reference in New Issue
Block a user