<commit_before>/* 
* @Author: <NAME>
* @Date:   2015-12-14 11:32:58
* @Last Modified 2015-12-16
*/

'use strict';

import {Waterline} from '@nxus/storage'
import { Crypto } from 'cryptojs'
import crypto from 'crypto'
import _ from 'underscore'

const randomSalt = () => {
  try {
    let buf = crypto.randomBytes(24)
    return buf.toString('hex')
  }
  catch (ex) {
    console.dir(ex)
  }
}

const generateToken = (email) => {
  if (!email) email = new Date().getTime()
  return Crypto.MD5(email+randomSalt())
}

const hashPassword = (password, salt) => {
  const iterations = 42;
  let i = 0
  let hashed = password

  while (i < iterations) {
    hashed = Crypto.PBKDF2(hashed, salt, 256/8)
    i++
  }

  return hashed
}

const Roles = {
  Viewer: 10,
  Editor: 100,
  Admin: 1000
}

export default Waterline.Collection.extend({
  identity: 'user',
  connection: 'default',
  attributes: {
    email: 'string',
    nameFirst: 'string',
    nameLast: 'string',
    position: 'string',
    enabled: 'boolean',
    salt: { 
      type: 'string', 
      defaultsTo: randomSalt
    },
    passwordHash: 'string',
    verifyToken: { 
      type: 'string', 
      defaultsTo: generateToken<commit_msg>Setting email to be unique<commit_after>/* 
* @Author: <NAME>
* @Date:   2015-12-14 11:32:58
* @Last Modified 2016-02-08
*/

'use strict';

import {Waterline} from '@nxus/storage'
import { Crypto } from 'cryptojs'
import crypto from 'crypto'
import _ from 'underscore'

const randomSalt = () => {
  try {
    let buf = crypto.randomBytes(24)
    return buf.toString('hex')
  }
  catch (ex) {
    console.dir(ex)
  }
}

const generateToken = (email) => {
  if (!email) email = new Date().getTime()
  return Crypto.MD5(email+randomSalt())
}

const hashPassword = (password, salt) => {
  const iterations = 42;
  let i = 0
  let hashed = password

  while (i < iterations) {
    hashed = Crypto.PBKDF2(hashed, salt, 256/8)
    i++
  }

  return hashed
}

const Roles = {
  Viewer: 10,
  Editor: 100,
  Admin: 1000
}

export default Waterline.Collection.extend({
  identity: 'user',
  connection: 'default',
  attributes: {
    email: {
      type: 'string',
      unique: true
    },
    nameFirst: 'string',
    nameLast: 'string',
    position: 'string',
    enabled: 'boolean',
    salt: { 
      type: 'string', 
      defaultsTo: randomSalt
    },
    passwordHash: '<PASSWORD>',
    verifyToken: { 
      type: 'string', 
      defaultsTo: generateToken
{'fraction_non_alphanumeric': 0.1454175152749491, 'fraction_numerical': 0.034215885947046845, 'mean_word_length': 2.987012987012987, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, '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': '3065434', 'n_tokens_mistral': 931, 'n_tokens_neox': 843, 'n_words': 222}