user.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:TigerHost 作者: naphatkrit 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号