コード例 #1
0
def account_update(current_password, **kwargs):
    client = AccountClient()
    profile = client.get_profile()
    new_profile = profile.copy()
    if not any(kwargs.values()):
        for field in profile:
            new_profile[field] = click.prompt(field.replace("_",
                                                            " ").capitalize(),
                                              default=profile[field])
            if field == "email":
                validate_email(new_profile[field])
            if field == "username":
                validate_username(new_profile[field])
    else:
        new_profile.update(
            {key: value
             for key, value in kwargs.items() if value})
    client.update_profile(new_profile, current_password)
    click.secho("Profile successfully updated!", fg="green")
    username_changed = new_profile["username"] != profile["username"]
    email_changed = new_profile["email"] != profile["email"]
    if not username_changed and not email_changed:
        return None
    try:
        client.logout()
    except AccountNotAuthorized:
        pass
    if email_changed:
        return click.secho(
            "Please check your mail to verify your new email address and re-login. ",
            fg="yellow",
        )
    return click.secho("Please re-login.", fg="yellow")
コード例 #2
0
def account_destroy():
    client = AccountClient()
    click.confirm(
        "Are you sure you want to delete the %s user account?\n"
        "Warning! All linked data will be permanently removed and can not be restored."
        % client.get_account_info().get("profile").get("username"),
        abort=True,
    )
    client.destroy_account()
    try:
        client.logout()
    except AccountNotAuthorized:
        pass
    return click.secho(
        "User account has been destroyed.",
        fg="green",
    )
コード例 #3
0
def account_logout():
    client = AccountClient()
    client.logout()
    return click.secho("Successfully logged out!", fg="green")