<commit_before>window.matrixRegistration = {
    endpoint: location.origin + "/_matrix/client/api/v1/register"
};

var setupCaptcha = function() {
    if (!window.matrixRegistrationConfig) {
        return;
    }
    $.get(matrixRegistration.endpoint, function(response) {
        var serverExpectsCaptcha = false;
        for (var i=0; i<response.flows.length; i++) {
            var flow = response.flows[i];
            if ("m.login.recaptcha" === flow.type) {
                serverExpectsCaptcha = true;
                break;
            }
        }
        if (!serverExpectsCaptcha) {
            console.log("This server does not require a captcha.");
            return;
        }
        console.log("Setting up ReCaptcha for "+matrixRegistration.endpoint);
        var public_key = window.matrixRegistrationConfig.recaptcha_public_key;
        if (public_key === undefined) {
            console.error("No public key defined for captcha!");
            return;
        }
        Recaptcha.create(public_key,
        "regcaptcha",
        {
            theme: "red",
            callback: Recaptcha.focus_response_field
        });
        window.matrixRegistration.isUsingRecaptcha = true;
    }).error(errorFunc);
    
};

var submitCaptcha = function(user, pwd) {
    var challengeToken = Recaptcha.get_challenge();
    var captchaEntry = Recaptcha.get_response();
    var data = {
        type: "m.login.recaptcha",
        challenge: challengeToken,
        response: captchaEntry
    };
    console.log("Submitting captcha");
    $.post(matrixRegistration.endpoint, JSON.stringify(data), function(response) {
        console.log("Success -> "+JSON.stringify(response));<commit_msg>Set user-visible error when the server is misconfigured.<commit_after>window.matrixRegistration = {
    endpoint: location.origin + "/_matrix/client/api/v1/register"
};

var setupCaptcha = function() {
    if (!window.matrixRegistrationConfig) {
        return;
    }
    $.get(matrixRegistration.endpoint, function(response) {
        var serverExpectsCaptcha = false;
        for (var i=0; i<response.flows.length; i++) {
            var flow = response.flows[i];
            if ("m.login.recaptcha" === flow.type) {
                serverExpectsCaptcha = true;
                break;
            }
        }
        if (!serverExpectsCaptcha) {
            console.log("This server does not require a captcha.");
            return;
        }
        console.log("Setting up ReCaptcha for "+matrixRegistration.endpoint);
        var public_key = window.matrixRegistrationConfig.recaptcha_public_key;
        if (public_key === undefined) {
            console.error("No public key defined for captcha!");
            setFeedbackString("Misconfigured captcha for server. Contact server admin.");
            return;
        }
        Recaptcha.create(public_key,
        "regcaptcha",
        {
            theme: "red",
            callback: Recaptcha.focus_response_field
        });
        window.matrixRegistration.isUsingRecaptcha = true;
    }).error(errorFunc);
    
};

var submitCaptcha = function(user, pwd) {
    var challengeToken = Recaptcha.get_challenge();
    var captchaEntry = Recaptcha.get_response();
    var data = {
        type: "m.login.recaptcha",
        challenge: challengeToken,
        response: captchaEntry
    };
    console.log("Submitting captcha");
    $.post(matrixRegistration.endpoint, JSON.stringify(data), function(response) {
        console.log("Success -> "+JSON.stringify(response));
{'fraction_non_alphanumeric': 0.1141966562765656, 'fraction_numerical': 0.0011334655709832814, 'mean_word_length': 2.3715377268385867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5548243', 'n_tokens_mistral': 974, 'n_tokens_neox': 961, 'n_words': 195}