<commit_before>GroupAccounts = {};
var ValidEmail = Match.Where (function (x) {
    check (x, String);
    return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i.test (x);
});

var ValidDigestPassword = Match.Where (function (x){
    check (x, { digest:String, algorithm:String});
    return 'sha-256' == x.algorithm;
});

if (Meteor.isClient) {
    Accounts.onLogin (function () {
        //console.log ('[GroupAccounts.onLogin]');
    });
    Accounts.onLoginFailure (function () {
        //console.log ('[GroupAccounts.onGroupAccountLoginFailure]');
    });
    GroupAccounts.createAccount = function (params, callback) {
        //console.log ('[GroupAccounts.createAccount]', params);
        if (callback) { check (callback, Function); }
        check (params, Match.ObjectIncluding ({ accountAdminPassword: String }));
        params.accountAdminPassword = {
            digest: SHA256 (params.accountAdminPassword),
            algorithm: 'sha-256' };
        Meteor.call ('groupaccount/createAccount', params, callback);
    };

    GroupAccounts.configure = function ( params, callback) {
        Meteor.call ('groupaccount/configure', params, callback);
    };

    GroupAccounts.joinGroup = function (params, callback) {
        //console.log ('[GroupAccounts.joinGroup]', params);
        if (callback) { check (callback, Function); }
        check (params, Match.ObjectIncluding ({
            accountSelector: String,
            memberPassword: String 
	    }));
        params.memberPassword = {
            digest: SHA256 (params.memberPassword),
            algorithm: 'sha-256' };
        Meteor.call ('groupaccount/joinGroup', params, callback);
    };

    GroupAccounts.removeMember = function (params, callback) {
        //console.log ('[GroupAccounts.removeMember]', params);
        if (callback) { check (callback, Function); }
        check (params, Match.ObjectIncluding ({
            memberSelector: String }));
        Meteor.call ('groupaccount/removeMember', params, callback);
    };

    GroupAccounts.activateMember = function (params, callback) {
        if (callback) { check (callback, Function); }
        check (params, Match.ObjectIncluding ({
            memberSelector: String}));
        Meteor.call ('groupaccount/activateMember', params, callback);
    };

    Meteor.loginWithGroupAccount = function (params, callback) {
        //console.log ('[Meteor.loginWithGroupAccount]', params);
        check (params, Match.ObjectIncluding ({
            memberPassword:String,
            memberSelector:String
        }));
        params.memberPassword = {
            digest: SHA256 (params.memberPassword),
            algorithm: 'sha-256'
        };
        Accounts.callLoginMethod ({
            methodArguments: [{groupaccount:params}],
            userCallback: callback
        });
    };

    //
    // Helper shim to override template renderFunctions
    // Inspired by template-replaces() from aldeed:template-extension package. Good stuff.
    Template.prototype._gaOverride = function (replacement){
        console.log ('[groupAccountManager._gaOverride] this:', this);
        if (typeof replacement === 'string') {
            replacement = Template[replacement];
        }
        console.log ('[groupAccountManager._gaOverride] replacement:', replacement);
        if (replacement && replacement instanceof Blaze.Template ) {
            this.renderFunction = replacement.renderFunction;
        }
    }

}

if (Meteor.isServer) {

    var bcrypt = NpmModuleBcrypt;
    var bcryptHash = Meteor.wrapAsync(bcrypt.hash);
    var bcryptCompare = Meteor.wrapAsync(bcrypt.compare);

    Accounts.registerLoginHandler ("groupaccount", function (params){
        if (!params.groupaccount) {
            return undefined;
        }

        params = params.groupaccount;
        check (params, Match.ObjectIncluding ({
            accountSelector: String,
            memberSelector: String,
            memberPassword: <PASSWORD>
        }));

        //console.log ('[GroupAccounts.loginHandler] accountSelector:', params.accountSelector);
        var group = Meteor.users.findOne ({username: params.accountSelector});
        if (!group) {<commit_msg>clean up log messages.<commit_after>GroupAccounts = {};
var ValidEmail = Match.Where (function (x) {
    check (x, String);
    return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i.test (x);
});

var ValidDigestPassword = Match.Where (function (x){
    check (x, { digest:String, algorithm:String});
    return 'sha-256' == x.algorithm;
});

if (Meteor.isClient) {
    Accounts.onLogin (function () {
        //console.log ('[GroupAccounts.onLogin]');
    });
    Accounts.onLoginFailure (function () {
        //console.log ('[GroupAccounts.onGroupAccountLoginFailure]');
    });
    GroupAccounts.createAccount = function (params, callback) {
        //console.log ('[GroupAccounts.createAccount]', params);
        if (callback) { check (callback, Function); }
        check (params, Match.ObjectIncluding ({ accountAdminPassword: String }));
        params.accountAdminPassword = {
            digest: SHA256 (params.accountAdminPassword),
            algorithm: 'sha-256' };
        Meteor.call ('groupaccount/createAccount', params, callback);
    };

    GroupAccounts.configure = function ( params, callback) {
        Meteor.call ('groupaccount/configure', params, callback);
    };

    GroupAccounts.joinGroup = function (params, callback) {
        //console.log ('[GroupAccounts.joinGroup]', params);
        if (callback) { check (callback, Function); }
        check (params, Match.ObjectIncluding ({
            accountSelector: String,
            memberPassword: String 
	    }));
        params.memberPassword = {
            digest: SHA256 (params.memberPassword),
            algorithm: 'sha-256' };
        Meteor.call ('groupaccount/joinGroup', params, callback);
    };

    GroupAccounts.removeMember = function (params, callback) {
        //console.log ('[GroupAccounts.removeMember]', params);
        if (callback) { check (callback, Function); }
        check (params, Match.ObjectIncluding ({
            memberSelector: String }));
        Meteor.call ('groupaccount/removeMember', params, callback);
    };

    GroupAccounts.activateMember = function (params, callback) {
        if (callback) { check (callback, Function); }
        check (params, Match.ObjectIncluding ({
            memberSelector: String}));
        Meteor.call ('groupaccount/activateMember', params, callback);
    };

    Meteor.loginWithGroupAccount = function (params, callback) {
        //console.log ('[Meteor.loginWithGroupAccount]', params);
        check (params, Match.ObjectIncluding ({
            memberPassword:String,
            memberSelector:String
        }));
        params.memberPassword = {
            digest: SHA256 (params.memberPassword),
            algorithm: 'sha-256'
        };
        Accounts.callLoginMethod ({
            methodArguments: [{groupaccount:params}],
            userCallback: callback
        });
    };

    //
    // Helper shim to override template renderFunctions
    // Inspired by template-replaces() from aldeed:template-extension package. Good stuff.
    Template.prototype._gaOverride = function (replacement){
        if (typeof replacement === 'string') {
            replacement = Template[replacement];
        }
        if (replacement && replacement instanceof Blaze.Template ) {
            this.renderFunction = replacement.renderFunction;
        }
    }

}

if (Meteor.isServer) {

    var bcrypt = NpmModuleBcrypt;
    var bcryptHash = Meteor.wrapAsync(bcrypt.hash);
    var bcryptCompare = Meteor.wrapAsync(bcrypt.compare);

    Accounts.registerLoginHandler ("groupaccount", function (params){
        if (!params.groupaccount) {
            return undefined;
        }

        params = params.groupaccount;
        check (params, Match.ObjectIncluding ({
            accountSelector: String,
            memberSelector: String,
            memberPassword: <PASSWORD>
        }));

        //console.log ('[GroupAccounts.loginHandler] accountSelector:', params.accountSelector);
        var group = Meteor.users.findOne ({username: params.accountSelector});
        if (!group) {
{'fraction_non_alphanumeric': 0.13040319651289503, 'fraction_numerical': 0.006538321830730113, 'mean_word_length': 2.653250773993808, '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': '806101', 'n_tokens_mistral': 2268, 'n_tokens_neox': 2183, 'n_words': 473}