Skip to content
21 changes: 7 additions & 14 deletions evalai/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@ def login(ctx):
password = click.prompt("Enter password", type=str, hide_input=True)
token = get_user_auth_token_by_login(username, password)

if os.path.exists(AUTH_TOKEN_PATH):
with open(str(AUTH_TOKEN_PATH), "w") as TokenFile:
try:
json.dump(token, TokenFile)
except (OSError, IOError) as e:
echo(e)
else:
if not os.path.exists(AUTH_TOKEN_DIR):
os.makedirs(AUTH_TOKEN_DIR)
with open(str(AUTH_TOKEN_PATH), "w+") as TokenFile:
try:
json.dump(token, TokenFile)
except (OSError, IOError) as e:
echo(e)
if not os.path.exists(AUTH_TOKEN_DIR):
os.makedirs(AUTH_TOKEN_DIR)
with open(AUTH_TOKEN_PATH, "w") as TokenFile:
try:
json.dump(token, TokenFile)
except (OSError, IOError) as e:
echo(e)

echo(style("\nLogged in successfully!", bold=True))