<commit_before>var mongoose = require('mongoose');
var _ = require('underscore');
var fs = require('fs');

module.exports.getAllSites = function(req, res, next) {
    mongoose.model('site').find(function(err, sites) {
        if (err) {
            console.log(err);
            next();
        } else {
            // Remove the users password from the display
            var ret = [];
            sites.forEach(function(element) {
                ret.push(_.omit(element.toObject(), ['__v', 'password']));
            });
            res.send(ret);
        }
    });
};

module.exports.getSite = function(req, res, next) {
    mongoose.model('site').findOne({ _id: req.params.id }, function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            res.send(_.omit(site.toObject(), ['__v', 'password']));
        }
    });
};

module.exports.getSiteScript = function(req, res, next) {
    mongoose.model('site').findOne({ _id: req.params.id }, function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            var content = _.omit(site.toObject(), ['__v', 'password']);
            console.log(content);
            fs.readFile('templates/clientScript.js', function(err, data){
                console.log(data);
                res.status(200).send(_.template(data.toString())( content));
            })
        }
    });
};

module.exports.updateSite = function(req, res, next) {
    mongoose.model('site').findByIdAndUpdate(req.params.id, req.body, function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            res.send(_.omit(site.toObject(), ['__v', 'password']));
        }
    });
};

module.exports.deleteSite = function(req, res, next) {
    mongoose.model('site').findOneAndRemove(req.params.id, function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            res.status(204);
        }
    });
};

module.exports.createSite = function(req, res, next) {
    var Site = require('../models/site');
    var data = req.body;

    var site = new Site({
        user: req.user.id,
        name: data.name,
        login: data.login,
        password: <PASSWORD>,
        fields: data.fields
    });

    site.save(function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            res.send(site);
        }
    });
};<commit_msg>Enabled cross domain scripting for client script<commit_after>var mongoose = require('mongoose');
var _ = require('underscore');
var fs = require('fs');

module.exports.getAllSites = function(req, res, next) {
    mongoose.model('site').find(function(err, sites) {
        if (err) {
            console.log(err);
            next();
        } else {
            // Remove the users password from the display
            var ret = [];
            sites.forEach(function(element) {
                ret.push(_.omit(element.toObject(), ['__v', 'password']));
            });
            res.send(ret);
        }
    });
};

module.exports.getSite = function(req, res, next) {
    mongoose.model('site').findOne({ _id: req.params.id }, function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            res.send(_.omit(site.toObject(), ['__v', 'password']));
        }
    });
};

module.exports.getSiteScript = function(req, res, next) {

    mongoose.model('site').findOne({ _id: req.params.id }, function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            var content = _.omit(site.toObject(), ['__v', 'password']);
            fs.readFile('templates/clientScript.js', function(err, data){
                res.header("Access-Control-Allow-Origin", "*");
                res.header("Access-Control-Allow-Headers", "X-Requested-With");
                res.status(200).send(_.template(data.toString())( content));
            })
        }
    });
};

module.exports.updateSite = function(req, res, next) {
    mongoose.model('site').findByIdAndUpdate(req.params.id, req.body, function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            res.send(_.omit(site.toObject(), ['__v', 'password']));
        }
    });
};

module.exports.deleteSite = function(req, res, next) {
    mongoose.model('site').findOneAndRemove(req.params.id, function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            res.status(204);
        }
    });
};

module.exports.createSite = function(req, res, next) {
    var Site = require('../models/site');
    var data = req.body;

    var site = new Site({
        user: req.user.id,
        name: data.name,
        login: data.login,
        password: <PASSWORD>,
        fields: data.fields
    });

    site.save(function(err, site) {
        if (err) {
            console.log(err);
            next();
        } else {
            res.send(site);
        }
    });
};
{'fraction_non_alphanumeric': 0.16936269732995518, 'fraction_numerical': 0.0023387253946599105, 'mean_word_length': 1.8638392857142858, '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': '1029219', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1551, 'n_words': 281}