<commit_before>
const UserApi = {
  _createSession: (req, user) => {
    return req.models.Session.create({
      userId: user.id,
    }).then(session => {
      req.session = session;
      return session;
    });
  },

  hasSession: (req, res, next) => {
    next(req.session && req.session.userId ? null : 'You are not logged in');
  },

  populateSession: (req, res, next) => {
    return req.models.Session.findOne({ token: req.cookie ? req.cookie.token : '' })
      .then(session => {
        req.session = session;
      }).finally(() => {
        next();
      });
  },

  signIn: (req, res, next) => {
    const email = req.body.email;
    const password = <PASSWORD>;
    let user;
    return req.models.User.findOne({ email })
      .then(_user => {
        user = _user;
        return user.hasPasswordsEquals(password);
      })
      .then(UserApi._createSession.bind(null, req))
      .then(session => {
        res.send({ token: session.token, user: user.toObject() });
      }, next);
  },

  signUp: (req, res, next) => {
    const email = req.body.email;
    const password = <PASSWORD>;
    const name = req.body.name;
    let user;
    return req.models.User.create({ email, password, name })
      .then(_user => {
        user = _user;
        return UserApi._createSession(req, user);
      })
      .then(session => {
        res.send({ token: session.token, user: user.toObject() });
      }, next);
  },

  me: (req, res, next) => {
    return req.models.User.findById(req.session.userId)
      .then(user => {
        res.send(user.toObject());
      }, next);
  },

  get: (req, res, next) => {
    return req.models.User.findById(req.params.userId)
      .then(user => {
        res.send(user.toProfile());
      }, next);
  },
};

module.exports = UserApi;<commit_msg>Added signout<commit_after>
const UserApi = {
  _createSession: (req, user) => {
    return req.models.Session.create({
      userId: user.id,
    }).then(session => {
      req.session = session;
      return session;
    });
  },

  hasSession: (req, res, next) => {
    next(req.session && req.session.userId ? null : 'You are not logged in');
  },

  populateSession: (req, res, next) => {
    return req.models.Session.findOne({ token: req.cookie ? req.cookie.token : '' })
      .then(session => {
        req.session = session;
      }).finally(() => {
        next();
      });
  },

  signIn: (req, res, next) => {
    const email = req.body.email;
    const password = <PASSWORD>;
    let user;
    return req.models.User.findOne({ email })
      .then(_user => {
        user = _user;
        return user.hasPasswordsEquals(password);
      })
      .then(UserApi._createSession.bind(null, req))
      .then(session => {
        res.send({ token: session.token, user: user.toObject() });
      }, next);
  },

  signUp: (req, res, next) => {
    const email = req.body.email;
    const password = <PASSWORD>;
    const name = req.body.name;
    let user;
    return req.models.User.create({ email, password, name })
      .then(_user => {
        user = _user;
        return UserApi._createSession(req, user);
      })
      .then(session => {
        res.send({ token: session.token, user: user.toObject() });
      }, next);
  },

  signOut: (req, res, next) => {
    return req.models.Session.findById(req.session.id)
      .then(session => {
        return session.destroy();
      })
      .then(() => {
        res.send();
      }, next);
  },

  me: (req, res, next) => {
    return req.models.User.findById(req.session.userId)
      .then(user => {
        res.send(user.toObject());
      }, next);
  },

  get: (req, res, next) => {
    return req.models.User.findById(req.params.userId)
      .then(user => {
        res.send(user.toProfile());
      }, next);
  },
};

module.exports = UserApi;
{'fraction_non_alphanumeric': 0.1757464641173389, 'fraction_numerical': 0.0, 'mean_word_length': 2.2446898895497025, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 42, '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': '3067429', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1250, 'n_words': 258}