Verify credentials on "cards add"
This commit is contained in:
parent
eb0fd40899
commit
26a7239020
1 changed files with 19 additions and 5 deletions
24
nauta.py
24
nauta.py
|
@ -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
|
||||||
|
|
||||||
username, password = select_card()
|
if args.username:
|
||||||
if username is None:
|
username = args.username
|
||||||
print("No card available, add one with 'nauta cards add'")
|
password = get_password(username)
|
||||||
return
|
if password is None:
|
||||||
|
print("Invalid card: {}".format(args.username))
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
username, password = select_card()
|
||||||
|
if username is None:
|
||||||
|
print("No card available, add one with 'nauta cards add'")
|
||||||
|
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))
|
||||||
|
|
Loading…
Reference in a new issue