<commit_before>'use strict';

/**
 * Module dependencies.
 */
var _ = require('lodash'),
	fs = require('fs'),
	path = require('path'),
	errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
	mongoose = require('mongoose'),
	passport = require('passport'),
	logger = require('tracer').console(),
	User = mongoose.model('User');



/**
 * Add a favorite shortcut to the user
 */
exports.addFavorite = function(req, res, next) {
	if (req.body.action === 'add') {
		var isNotDuplicate = req.user.favorites.indexOf(req.body.shortcut._id) === -1;
		if (isNotDuplicate) {
			req.user.favorites.push(req.body.shortcut._id);
		}
	} else if (req.body.action === 'remove') {
		_.remove(req.user.favorites, function(favorite) {
			return favorite.toString() === req.body.shortcut._id;
		});
	}
	req.body = {};
	next();
}

/**
 * Update user details
 */
exports.update = function(req, res) {
	// Init Variables
	var user = req.user;

	// For security measurement we remove the roles from the req.body object
	delete req.body.roles;

	if (user) {
		// Merge existing user
		user = _.extend(user, req.body);<commit_msg>refactoring<commit_after>'use strict';

/**
 * Module dependencies.
 */
var _ = require('lodash'),
	fs = require('fs'),
	path = require('path'),
	errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
	mongoose = require('mongoose'),
	passport = require('passport'),
	logger = require('tracer').console(),
	User = mongoose.model('User');



/**
 * Add a favorite shortcut to the user
 */
exports.addFavorite = function(req, res, next) {
	var action = req.body.action;
	if (action === 'add') {
		var isNotDuplicate = req.user.favorites.indexOf(req.body.shortcut._id) === -1;
		if (isNotDuplicate) {
			req.user.favorites.push(req.body.shortcut._id);
		}
	} else if (action === 'remove') {
		_.remove(req.user.favorites, function(favorite) {
			return favorite.toString() === req.body.shortcut._id;
		});
	}
	req.body = {};
	next();
}

/**
 * Update user details
 */
exports.update = function(req, res) {
	// Init Variables
	var user = req.user;

	// For security measurement we remove the roles from the req.body object
	delete req.body.roles;

	if (user) {
		// Merge existing user
		user = _.extend(user, req.body);
{'fraction_non_alphanumeric': 0.17568152315015145, 'fraction_numerical': 0.0008654262224145391, 'mean_word_length': 3.8983050847457625, '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': '3022401', 'n_tokens_mistral': 810, 'n_tokens_neox': 779, 'n_words': 170}