<commit_before>var sign;

jQuery(function($) {
    // NB.  By browsing secondary server source code, I have
    // discovered that 'user is not authenticated as target user' is
    // the only acceptable error message here.
    //
    // See: static/shared/user.js, primaryUserAuthenticationInfo
    var ifLoggedIn = function(email, thunk) {
        $.ajax({
            type: 'POST',
            crossDomain: true,
            url: '/browserid/logged_in_p.pl',
            dataType: 'json',
            data: { email: email },
            success: function(data, status, xhr) {
                console.log('Logged in: ' + data.logged_in_p);
                if (data.logged_in_p === 0) {
                    console.log('* Not logged in.');
                    return navigator.id.raiseProvisioningFailure('user is not authenticated as target user');
                } else {
                    thunk();
                }
            },
            error: function(data, status, xhr) {
                console.log('Logged in: no.');
                return navigator.id.raiseProvisioningFailure('user is not authenticated as target user');
            }
        });
    };

    sign = function(email, pubkey, cert_duration) {
        console.log('email: '    + email);
        console.log('pubkey: '); console.log(pubkey);
        console.log('duration: ' + cert_duration);
        $.ajax({
            type: 'POST',
            crossDomain: true,
            url: '/browserid/sign.pl',
            dataType: 'json',
            data: { email: email, pubkey: JSON.stringify(pubkey), duration: cert_duration },
            success: function(data, status, xhr) {
		console.log('Success!');
                console.log(data);
                navigator.id.registerCertificate(data.signature);
            },
            error: function(data, status, xhr) {
                return navigator.id.raiseProvisioningFailure(data.responseText);
            }
        });
    };

    navigator.id.beginProvisioning(function(email, cert_duration) {
        console.log('email: ' + email);
        console.log('cert_duration: ' + cert_duration);
        ifLoggedIn(email, function() {
            navigator.id.genKeyPair(function(pubkey) {
                sign(email, pubkey, cert_duration);
            });
        });
    });
});
<commit_msg>Adapt to recent protocol change.<commit_after>var sign;

jQuery(function($) {
    // NB.  By browsing secondary server source code, I have
    // discovered that 'user is not authenticated as target user' is
    // the only acceptable error message here.
    //
    // See: static/shared/user.js, primaryUserAuthenticationInfo
    var ifLoggedIn = function(email, thunk) {
        $.ajax({
            type: 'POST',
            crossDomain: true,
            url: '/browserid/logged_in_p.pl',
            dataType: 'json',
            data: { email: email },
            success: function(data, status, xhr) {
                console.log('Logged in: ' + data.logged_in_p);
                if (data.logged_in_p === 0) {
                    console.log('* Not logged in.');
                    return navigator.id.raiseProvisioningFailure('user is not authenticated as target user');
                } else {
                    thunk();
                }
            },
            error: function(data, status, xhr) {
                console.log('Logged in: no.');
                return navigator.id.raiseProvisioningFailure('user is not authenticated as target user');
            }
        });
    };

    sign = function(email, pubkey, cert_duration) {
        console.log('email: '    + email);
        console.log('pubkey: '); console.log(pubkey);
        console.log('duration: ' + cert_duration);
        $.ajax({
            type: 'POST',
            crossDomain: true,
            url: '/browserid/sign.pl',
            dataType: 'json',
            data: { email: email, pubkey: JSON.stringify(pubkey), duration: cert_duration },
            success: function(data, status, xhr) {
		console.log('Success!');
                console.log(data);
                navigator.id.registerCertificate(data.signature);
            },
            error: function(data, status, xhr) {
                return navigator.id.raiseProvisioningFailure(data.responseText);
            }
        });
    };

    navigator.id.beginProvisioning(function(email, cert_duration) {
        console.log('email: ' + email);
        console.log('cert_duration: ' + cert_duration);
        ifLoggedIn(email, function() {
            navigator.id.genKeyPair(function(pubkey) {
                if (typeof(pubkey) === 'string') {
                    pubkey = JSON.parse(pubkey);
                }
                sign(email, pubkey, cert_duration);
            });
        });
    });
});
{'fraction_non_alphanumeric': 0.12531276063386154, 'fraction_numerical': 0.0004170141784820684, 'mean_word_length': 1.7458500286204923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1619926', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1289, 'n_words': 283}