<commit_before>var crypto = require('crypto');

var _ = require('lodash');
var uuid = require('node-uuid');
var Promise = require('es6-promise').Promise;

var leaderboard = require('./leaderboard');
var utils = require('./utils');


const MAX_LEADERBOARD_INCR = 10;
const TIME_UPDATE_PLAYTIME = 1000 * 60 * 5;  // 5 minutes


function newUser(client, email) {
    var userData = {
        username: email.split('@')[0],
        email: email,
        permissions: {
            developer: false,
            reviewer: false,
            admin: false
        },
        homepage: '',
        support: '',
        companySlug: '',
        companyName: '',
        dateLastLogin: utils.now(),
        id: uuid.v4()
    };
    client.hset('users', userData.id, JSON.stringify(userData));
    client.hset('usersByEmail', email, userData.id);
    // TODO: Figure out a way to store users by username.
    return userData;
}
exports.newUser = newUser;


function updateUser(client, userID, opts, callback) {
    getUserFromID(client, userID, function(err, userData) {
        if (err) {
            callback(err);
            return;
        }

        var newUserData = _.clone(userData);

        var updateFunctions = {
            companySlug: updateCompanySlug,
            email: updateEmail,
            username: updateUsername
        };

        Promise.all(Object.keys(opts).map(function(key) {
            var updateFunction = updateFunctions[key];
            var value = opts[key];
            if (updateFunction) {
                return updateFunction(value);
            }
            else {
                return updateProperty(key, value);
            }
        })).then(updateClient).catch(function(err) {
            console.error('Error updating user:', err);
            callback(err.message);
        });

        // fallback update method
        function updateProperty(key, newValue) {
            return new Promise(function(resolve, reject) {
                newUserData[key] = newValue;<commit_msg>Removed an entire line of code<commit_after>var crypto = require('crypto');

var _ = require('lodash');
var uuid = require('node-uuid');
var Promise = require('es6-promise').Promise;

var leaderboard = require('./leaderboard');
var utils = require('./utils');


const MAX_LEADERBOARD_INCR = 10;
const TIME_UPDATE_PLAYTIME = 1000 * 60 * 5;  // 5 minutes


function newUser(client, email) {
    var userData = {
        username: email.split('@')[0],
        email: email,
        permissions: {
            developer: false,
            reviewer: false,
            admin: false
        },
        homepage: '',
        support: '',
        companySlug: '',
        companyName: '',
        dateLastLogin: utils.now(),
        id: uuid.v4()
    };
    client.hset('users', userData.id, JSON.stringify(userData));
    client.hset('usersByEmail', email, userData.id);
    // TODO: Figure out a way to store users by username.
    return userData;
}
exports.newUser = newUser;


function updateUser(client, userID, opts, callback) {
    getUserFromID(client, userID, function(err, userData) {
        if (err) {
            callback(err);
            return;
        }

        var newUserData = _.clone(userData);

        var updateFunctions = {
            companySlug: updateCompanySlug,
            email: updateEmail,
            username: updateUsername
        };

        Promise.all(Object.keys(opts).map(function(key) {
            var updateFunction = updateFunctions[key];
            var value = opts[key];
            if (updateFunction) {
                return updateFunction(value);
            } else {
                return updateProperty(key, value);
            }
        })).then(updateClient).catch(function(err) {
            console.error('Error updating user:', err);
            callback(err.message);
        });

        // fallback update method
        function updateProperty(key, newValue) {
            return new Promise(function(resolve, reject) {
                newUserData[key] = newValue;
{'fraction_non_alphanumeric': 0.121077341240425, 'fraction_numerical': 0.006424511984185817, 'mean_word_length': 2.09480122324159, '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': '2164231', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1103, 'n_words': 260}