Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var bcrypt = require('bcryptjs');
- module.exports = function(sequelize, DataTypes) {
- var User = sequelize.define('User', {
- name: {
- type: DataTypes.STRING,
- allowNull: false
- },
- password: {
- type: DataTypes.STRING,
- allowNull: false
- },
- email: {
- type: DataTypes.STRING,
- primaryKey: true
- },
- phone: {
- type: DataTypes.STRING,
- allowNull: true
- }
- }, {
- instanceMethods:{
- updatePassword: function(newPass, callback){
- console.log("current pass in update: " + this.password);
- bcrypt.genSalt(10, function(err,salt){
- bcrypt.hash(newPass, salt, function(err, hashed){
- console.log("current pass: " + this.password);
- this.password = hashed;
- return callback();
- });
- });
- },
- comparePassword: function(password, callback){
- bcrypt.compare(password, this.password, function(err, isMatch){
- if(err) {
- throw err;
- }
- callback(isMatch);
- });
- }
- }
- ...
- console.log("current pass in update: " + this.password);
- var self = this;
- bcrypt.genSalt(10, function(err,salt){
- bcrypt.hash(newPass, salt, function(err, hashed){
- console.log("current pass: " + self.password);
- self.password = hashed;
- ...
- ...
- console.log("current pass in update: " + this.password);
- bcrypt.genSalt(10, (err,salt) => {
- bcrypt.hash(newPass, salt, (err, hashed) => {
- console.log("current pass: " + this.password);
- this.password = hashed; // note this in an arrow function refers to the 'uppper' this
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement