<commit_before>/* eslint-disable no-param-reassign */
/* eslint-disable no-underscore-dangle */
/* eslint-disable eqeqeq */

const jwt = require('jsonwebtoken');
const bcrypt = require('bcrypt-nodejs');

const User = require('../models/user');
const Document = require('../models/document');
const Role = require('../models/role');
const config = require('../config');

module.exports = {

  signup: (req, res) => {
    const user = new User();
    user.username = req.body.username;
    user.name = { firstname: req.body.firstname, lastname: req.body.lastname };
    user.email = req.body.email;
    user.password = <PASSWORD>.body.password;
    if (req.body.email === process.env.admin_email) {
      user.role = 'admin';
    }

    user.save((err) => {
      let error;
      if (err) {
        if (err.code === 11000) {
          error = err.message.match(/index:(.*?)_/)[1].trim();
          res.status(409).send({ message: `Duplicate ${error}.` });
        } else {
          if (!req.body.username) error = err.errors.username.message;
          if (!req.body.email) error = err.errors.email.message;
          if (!req.body.password) error = err.errors.password.message;
          if (!req.body.firstname) {
            error = err.errors['name.firstname'].message.replace(/name\./gi, '');
          }
          if (!req.body.lastname) {
            error = err.errors['name.lastname'].message.replace(/name\./gi, '');
          }
          res.status(400).send({ message: `Error creating user: ${error}` });
        }
      } else {
        const userData = {
          _id: user._id,
          email: user.email,
          role: user.role,
        };
        const dmsToken = jwt.sign(userData, config.secret, { expiresIn: 86400 });

        res.status(201).send({
          message: 'User created successfully.',<commit_msg>Code refactor<commit_after>/* eslint-disable no-param-reassign */
/* eslint-disable no-underscore-dangle */
/* eslint-disable eqeqeq */

const jwt = require('jsonwebtoken');
const bcrypt = require('bcrypt-nodejs');

const User = require('../models/user');
const Document = require('../models/document');
const Role = require('../models/role');
const config = require('../config');

module.exports = {

  signup: (req, res) => {
    const user = new User();
    user.username = req.body.username;
    user.name = { firstname: req.body.firstname, lastname: req.body.lastname };
    user.email = req.body.email;
    user.password = req.body.password;
    if (req.body.email === process.env.ADMIN_EMAIL) {
      user.role = 'admin';
    }

    user.save((err) => {
      let error;
      if (err) {
        if (err.code === 11000) {
          error = err.message.match(/index:(.*?)_/)[1].trim();
          res.status(409).send({ message: `Duplicate ${error}.` });
        } else {
          if (!req.body.username) error = err.errors.username.message;
          if (!req.body.email) error = err.errors.email.message;
          if (!req.body.password) error = err.errors.password.message;
          if (!req.body.firstname) {
            error = err.errors['name.firstname'].message.replace(/name\./gi, '');
          }
          if (!req.body.lastname) {
            error = err.errors['name.lastname'].message.replace(/name\./gi, '');
          }
          res.status(400).send({ message: `Error creating user: ${error}` });
        }
      } else {
        const userData = {
          _id: user._id,
          email: user.email,
          role: user.role,
        };
        const dmsToken = jwt.sign(userData, config.secret, { expiresIn: 86400 });

        res.status(201).send({
          message: 'User created successfully.',
{'fraction_non_alphanumeric': 0.17635817635817636, 'fraction_numerical': 0.01092001092001092, 'mean_word_length': 2.300900900900901, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '5366875', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1132, 'n_words': 220}