From 92c0f4a90ab8daaee1f311dcbb9192438dd7e945 Mon Sep 17 00:00:00 2001 From: "DESKTOP-DPA61F8\\Benedek" Date: Mon, 26 Apr 2021 23:17:34 +0200 Subject: [PATCH 1/2] Login errors --- client/client.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/client/client.py b/client/client.py index 10f3f9d..99335d4 100644 --- a/client/client.py +++ b/client/client.py @@ -56,13 +56,13 @@ def printCommand(): ' List content of current directory -> LST \n' + ' Upload file to current directory -> UPL \n' + ' Download file from current directory -> DNL \n' + - ' Login -> LIN \n' + + ' Login -> LIN \n' + ' Logout -> LOUT \n') def printCommandsWihtoutLogin(): print('\nYou must log in before issuing other commads!\n', - ' Login -> LIN \n', + ' Login -> LIN \n', ' Exit -> EXIT\n') @@ -99,14 +99,20 @@ while True: print("Invalid command format!") continue - if separatedCommand[0] == 'LIN' and len(separatedCommand) == 2: + if separatedCommand[0] == 'LIN' and len(separatedCommand) == 3: network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, separatedCommand[1], SERVER_PUBLIC_KEY) try: network.connectToServer(separatedCommand[2]) + response = network.recieveMessage().decode('UTF-8') + print(response) + if response == 'OK': + LOGGED_IN = True + else: + LOGGED_IN = False except Exception as e: print("Error: "+str(e)) + LOGGED_IN = False continue - LOGGED_IN = True continue if separatedCommand[0] == 'EXIT': @@ -181,3 +187,4 @@ while True: except Exception as e: print('Error: ' + str(e)) + continue From 863a42e982ba24fd504c405762ded2ab16c828ca Mon Sep 17 00:00:00 2001 From: "DESKTOP-DPA61F8\\Benedek" Date: Mon, 26 Apr 2021 23:25:53 +0200 Subject: [PATCH 2/2] OK --- client/client.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/client/client.py b/client/client.py index 99335d4..494fc4a 100644 --- a/client/client.py +++ b/client/client.py @@ -89,6 +89,7 @@ if not os.path.isfile(CONFIG_LOCATION) or os.stat(CONFIG_LOCATION).st_size == 0: SERVER_PUBLIC_KEY = loadPublicKey() CLIENT_PRIVATE_KEY = loadPrivateKey(PASSPHRASE) CLIENT_ADDRESS = loadAddress() +LOGGED_IN = False while True: command = input("Type a command:") @@ -99,21 +100,25 @@ while True: print("Invalid command format!") continue - if separatedCommand[0] == 'LIN' and len(separatedCommand) == 3: - network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, separatedCommand[1], SERVER_PUBLIC_KEY) - try: - network.connectToServer(separatedCommand[2]) - response = network.recieveMessage().decode('UTF-8') - print(response) - if response == 'OK': - LOGGED_IN = True - else: + if not LOGGED_IN: + if separatedCommand[0] == 'LIN' and len(separatedCommand) == 3: + network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, separatedCommand[1], SERVER_PUBLIC_KEY) + try: + network.connectToServer(separatedCommand[2]) + response = network.recieveMessage().decode('UTF-8') + print(response) + if response == 'OK': + LOGGED_IN = True + else: + LOGGED_IN = False + except Exception as e: + print("Error: "+str(e)) LOGGED_IN = False - except Exception as e: - print("Error: "+str(e)) - LOGGED_IN = False + continue continue - continue + else: + print('You are already logged in!') + if separatedCommand[0] == 'EXIT': sys.exit(1)