<commit_before>import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken';

import config from '../../../config';
import thinky from '../../utils/thinky';

const { r, type } = thinky;

const User = thinky.createModel('User', {
  type: type.string().default('User'),
  name: type.string(),
  id: type.string().options({ enforce_type: 'strict' }),
  displayName: type.string(),
  email: type.string().email(),
  provider: type.string(),
  data: type.any(),
  username: type.string().options({ enforce_type: 'strict' }),
  password: type.string(),
  createdAt: type.date().default(r.now()),
});

User.pre('save', function preSave(next) {
  const { password, provider } = this;

  if (!this.isModified('password') || provider !== 'local') {
    return next();
  }

  new Promise((resolve, reject) => {
    bcrypt.genSalt(10, (err, salt) => {
      if (err) {
        return reject(err);
      } else {
        resolve(salt);
      }
    });
  })
  .then((salt) => {
    bcrypt.hash(password, salt, (err, hash) => {
      if (err) { throw new Error(err); }

      this.password = <PASSWORD>;

      next(null);
    });
  })
  .catch(err => next(err));
});

User.define('validatePassword', function validatePassword(password) {
  const userPassword = this.password;

  return new Promise((resolve, reject) => {
    bcrypt.compare(password, userPassword, (err, isMatch) => {<commit_msg>update user model<commit_after>import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken';

import config from '../../../config';
import thinky from '../../utils/thinky';

const { r, type } = thinky;

const User = thinky.createModel('User', {
  type: type.string().default('User'),
  name: type.string(),
  id: type.string().options({ enforce_type: 'strict' }),
  displayName: type.string(),
  email: type.string().email(),
  provider: type.string(),
  data: type.any(),
  username: type.string().options({ enforce_type: 'strict' }),
  password: type.string(),
  createdAt: type.date().default(r.now()),
});

User.pre('save', function preSave(next) {
  const { password, provider } = this;

  if (!this.isModified('password') || provider !== 'local') {
    return next();
  }

  new Promise((resolve, reject) => {
    bcrypt.genSalt(10, (err, salt) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(salt);
    });
  })
  .then((salt) => {
    bcrypt.hash(password, salt, (err, hash) => {
      if (err) { throw new Error(err); }

      this.password = <PASSWORD>;

      next(null);
    });
  })
  .catch(err => next(err));
});

User.define('validatePassword', function validatePassword(password) {
  const userPassword = this.password;

  return new Promise((resolve, reject) => {
    bcrypt.compare(password, userPassword, (err, isMatch) => {
{'fraction_non_alphanumeric': 0.19412191582002902, 'fraction_numerical': 0.001451378809869376, 'mean_word_length': 3.418269230769231, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '6261677', 'n_tokens_mistral': 893, 'n_tokens_neox': 882, 'n_words': 203}