Verify credentials on "cards add"

This commit is contained in:
Andy Teijelo Pérez 2017-10-11 09:27:11 -04:00
parent eb0fd40899
commit 26a7239020

View file

@ -55,6 +55,13 @@ def parse_time(t):
except: except:
return 0 return 0
def get_password(username):
with dbm.open(CARDS_DB) as cards_db:
if not username in cards_db:
return None
info = json.loads(cards_db[username].decode())
return info['password']
def select_card(): def select_card():
cards = [] cards = []
with dbm.open(CARDS_DB) as cards_db: with dbm.open(CARDS_DB) as cards_db:
@ -81,12 +88,19 @@ def up(args):
print("Looks like you're already connected. Use 'nauta down' to log out.") print("Looks like you're already connected. Use 'nauta down' to log out.")
return return
if args.username:
username = args.username
password = get_password(username)
if password is None:
print("Invalid card: {}".format(args.username))
return
else:
username, password = select_card() username, password = select_card()
if username is None: if username is None:
print("No card available, add one with 'nauta cards add'") print("No card available, add one with 'nauta cards add'")
return return
username = username.decode() username = username.decode()
tl = time_left(username) tl = time_left(username)
print("Using card {}. Time left: {}".format(username, tl)) print("Using card {}. Time left: {}".format(username, tl))
log("Connecting with card {}. Time left on card: {}".format(username, tl)) log("Connecting with card {}. Time left on card: {}".format(username, tl))