Beispiel #1
0
def login(ctx, user_name, password):
    # type: (ApiCtx, str, str) -> ...
    headers = common_headers()
    url = "{}/user/login".format(ctx.api_base_url)

    password_value = b64_sha256(user_name + b64_sha256(password) + ctx.login_token)

    xml_data = """
    <?xml version:"1.0" encoding="UTF-8"?>
    <request>
        <Username>{}</Username>
        <Password>{}</Password>
        <password_type>4</password_type>
    </request>
    """.format(user_name, password_value)

#   setup headers
    headers['__RequestVerificationToken'] = ctx.login_token
    headers['X-Requested-With'] = 'XMLHttpRequest'

    r = post_to_url(url, xml_data, ctx, headers)

    if r['type'] == "response" and r['response'] == "OK":
        ctx.logged_in = True

    return r
def login(ctx: ApiCtx, user_name: str, password: str):
    headers = common_headers()
    url = "{}/user/login".format(API_URL)

    #   original JS code:
    #   psd = base64encode(
    #    SHA256(
    #        name +
    #        base64encode(
    #                       SHA256($('#password').val())
    #        ) +
    #        g_requestVerificationToken[0]
    #    )
    #   );

    password_value = b64_sha256(user_name + b64_sha256(password) + ctx.token)

    xml_data = """
    <?xml version:"1.0" encoding="UTF-8"?>
    <request>
        <Username>{}</Username>
        <Password>{}</Password>
        <password_type>4</password_type>
    </request>
    """.format(user_name, password_value)

    #   setup headers
    headers['__RequestVerificationToken'] = ctx.token
    headers['X-Requested-With'] = 'XMLHttpRequest'

    r = post_to_url(url, xml_data, ctx, headers)

    if r['type'] == "response" and r['response'] == "OK":
        ctx.logged_in = True

    return r