def login(ctx, username, api_key):
"""Logs the user in by asking for username and api_key
"""
if username is None:
username = click.prompt('Username (netID)')
click.echo()
if api_key is None:
click.echo('Please get your API key from ' +
click.style(_api_key_url, underline=True))
api_key = click.prompt('API key')
click.echo()
click.echo('Checking your credentials...', nl=False)
client = ApiClient(api_server_url=settings.API_SERVER_URL,
username=username, api_key=api_key)
try:
client.test_api_key()
except ApiClientAuthenticationError:
click.secho('invalid', bg='red', fg='black')
click.echo('Please try again.')
ctx.exit(code=exit_codes.OTHER_FAILURE)
else:
click.secho('OK', bg='green', fg='black')
user = User(username=username, api_key=api_key)
save_user(user)
评论列表
文章目录