Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. "use strict";
  2. var bcrypt = require('bcryptjs');
  3.  
  4. module.exports = function(sequelize, DataTypes) {
  5. var User = sequelize.define('User', {
  6. name: {
  7. type: DataTypes.STRING,
  8. allowNull: false
  9. },
  10. password: {
  11. type: DataTypes.STRING,
  12. allowNull: false
  13. },
  14. email: {
  15. type: DataTypes.STRING,
  16. primaryKey: true
  17. },
  18. phone: {
  19. type: DataTypes.STRING,
  20. allowNull: true
  21. }
  22. }, {
  23. instanceMethods:{
  24. updatePassword: function(newPass, callback){
  25. console.log("current pass in update: " + this.password);
  26. bcrypt.genSalt(10, function(err,salt){
  27. bcrypt.hash(newPass, salt, function(err, hashed){
  28. console.log("current pass: " + this.password);
  29. this.password = hashed;
  30. return callback();
  31. });
  32. });
  33. },
  34. comparePassword: function(password, callback){
  35. bcrypt.compare(password, this.password, function(err, isMatch){
  36. if(err) {
  37. throw err;
  38. }
  39. callback(isMatch);
  40. });
  41. }
  42. }
  43.  
  44. ...
  45. console.log("current pass in update: " + this.password);
  46. var self = this;
  47. bcrypt.genSalt(10, function(err,salt){
  48. bcrypt.hash(newPass, salt, function(err, hashed){
  49. console.log("current pass: " + self.password);
  50. self.password = hashed;
  51. ...
  52.  
  53. ...
  54. console.log("current pass in update: " + this.password);
  55. bcrypt.genSalt(10, (err,salt) => {
  56. bcrypt.hash(newPass, salt, (err, hashed) => {
  57. console.log("current pass: " + this.password);
  58. this.password = hashed; // note this in an arrow function refers to the 'uppper' this
  59. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement