Advertisement
Guest User

Untitled

a guest
Feb 24th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2. var crypto = require('crypto');
  3.  
  4. module.exports = function (sequelize, DataTypes) {
  5.     var User = sequelize.define('User', {
  6.         role: DataTypes.STRING,
  7.         name: DataTypes.STRING,
  8.         email: DataTypes.STRING,
  9.         password: {
  10.             type: DataTypes.STRING,
  11.             set: function (v) {
  12.                 var hash = crypto.pbkdf2Sync(v, this.getDataValue('email'), 7000, 72);
  13.                 hash = (new Buffer(hash, 'binary').toString('hex'));
  14.                 this.setDataValue('password', hash);
  15.             },
  16.             get:function(){
  17.                 return null;
  18.             }
  19.         },
  20.         phone: DataTypes.STRING,
  21.         status: DataTypes.INTEGER
  22.     }, {
  23.         paranoid: true,
  24.         classMethods: {
  25.             associate: function (models) {
  26.                 User.belongsTo(models.City);
  27.                 User.hasMany(models.CarWash);
  28.             },
  29.         },
  30.         instanceMethods: {
  31.             verifyPassword: function (password) {
  32.                 var hash = crypto.pbkdf2Sync(password, this.getDataValue('email'), 7000, 72);
  33.                 hash = (new Buffer(hash, 'binary').toString('hex'));
  34.                 return hash == this.getDataValue('password');
  35.             }
  36.         }
  37.     });
  38.     return User;
  39. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement