<commit_before>"use strict";

const mongoose = require('mongoose');
const bcrypt   = require('bcrypt-nodejs');
const moment = require('moment');

const Schema = mongoose.Schema;

const _ = require('lodash');

// Create a schema
let userSchema = new Schema({
    email: { type: String, unique: true, required: true },
    password: String,
    name: {
      first: String,
      middle: String,
      last: String
    },
    image: { type: String },
    isActivated: Boolean,
    isAdmin: Boolean,
    created: Date,
    updated: Date,
    confirmationKey: {
      key: String,
      created: Date
    },
    passwordResetKey: {
      key: String,
      created: Date
    },
    lastLogin: Date,
    social: [{
      provider: { type: String, required: true },
      id: { type: String, required: true },
      token: {
        value: { type: String, required: true },
        expires: { type: Date, required: true }
      },
      created: { type: Date, default: Date.now }
    }]
  },
  {
    toJSON : {
      transform: function (doc, ret) {
        // This is a temporary solution to expired FB images
        if ( ret.image && ret.social && ret.social[0].provider === 'facebook' ) {
          ret.image = 'https://graph.facebook.com/v2.8/' + ret.social[0].provider.id + '/picture?redirect=true';
        }
        delete ret.__v;
        delete ret.password;
        delete ret.isActivated;
        delete ret.isAdmin;
        delete ret.created;
        delete ret.updated;
        delete ret.confirmationKey;
        delete ret.passwordResetKey;
        delete ret.lastLogin;
        delete ret.social;
      }
    }
  });

userSchema.pre('save', function(next) {
  const currentDate = new Date();

  this.updated = currentDate;<commit_msg>References #64, fixed a bug.<commit_after>"use strict";

const mongoose = require('mongoose');
const bcrypt   = require('bcrypt-nodejs');
const moment = require('moment');

const Schema = mongoose.Schema;

const _ = require('lodash');

// Create a schema
let userSchema = new Schema({
    email: { type: String, unique: true, required: true },
    password: String,
    name: {
      first: String,
      middle: String,
      last: String
    },
    image: { type: String },
    isActivated: Boolean,
    isAdmin: Boolean,
    created: Date,
    updated: Date,
    confirmationKey: {
      key: String,
      created: Date
    },
    passwordResetKey: {
      key: String,
      created: Date
    },
    lastLogin: Date,
    social: [{
      provider: { type: String, required: true },
      id: { type: String, required: true },
      token: {
        value: { type: String, required: true },
        expires: { type: Date, required: true }
      },
      created: { type: Date, default: Date.now }
    }]
  },
  {
    toJSON : {
      transform: function (doc, ret) {
        // This is a temporary solution to expired FB images
        if ( ret.image && ret.social && ret.social[0].provider === 'facebook' ) {
          ret.image = 'https://graph.facebook.com/v2.8/' + ret.social[0].id + '/picture?redirect=true';
        }
        delete ret.__v;
        delete ret.password;
        delete ret.isActivated;
        delete ret.isAdmin;
        delete ret.created;
        delete ret.updated;
        delete ret.confirmationKey;
        delete ret.passwordResetKey;
        delete ret.lastLogin;
        delete ret.social;
      }
    }
  });

userSchema.pre('save', function(next) {
  const currentDate = new Date();

  this.updated = currentDate;
{'fraction_non_alphanumeric': 0.13036020583190394, 'fraction_numerical': 0.002858776443682104, 'mean_word_length': 2.2731524789522917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '463892', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1039, 'n_words': 283}