Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var crypto = require('crypto');
- module.exports = function (sequelize, DataTypes) {
- var User = sequelize.define('User', {
- role: DataTypes.STRING,
- name: DataTypes.STRING,
- email: DataTypes.STRING,
- password: {
- type: DataTypes.STRING,
- set: function (v) {
- var hash = crypto.pbkdf2Sync(v, this.getDataValue('email'), 7000, 72);
- hash = (new Buffer(hash, 'binary').toString('hex'));
- this.setDataValue('password', hash);
- },
- get:function(){
- return null;
- }
- },
- phone: DataTypes.STRING,
- status: DataTypes.INTEGER
- }, {
- paranoid: true,
- classMethods: {
- associate: function (models) {
- User.belongsTo(models.City);
- User.hasMany(models.CarWash);
- },
- },
- instanceMethods: {
- verifyPassword: function (password) {
- var hash = crypto.pbkdf2Sync(password, this.getDataValue('email'), 7000, 72);
- hash = (new Buffer(hash, 'binary').toString('hex'));
- return hash == this.getDataValue('password');
- }
- }
- });
- return User;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement