Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. var crypto = require("crypto");
  2. var mongoose = require("../libs/mongoose");
  3.  
  4. var schema = new Schema({
  5. username:{
  6. type:Stryng,
  7. unique:true,
  8. required:true
  9. },
  10. hashedPassword:{
  11. type:String,
  12. required:true
  13. },
  14. salt:{
  15. type:String,
  16. required:true
  17. },
  18. created:{
  19. type:Date,
  20. default:Date.now
  21. }
  22. });
  23. schema.metods.encryptPassword = function(password){
  24. return crypto.createHmac("sha1",this.salt).update(password).digest('hex');
  25. };
  26.  
  27. schema.virtual('password')
  28. .set(function(password){
  29. this._plainPassword = password;
  30. this.salt = Math.random();
  31. this.hashedPassword = this.encryptPassword(password);
  32. })
  33. .get(function(){return this._plainPassword});
  34. shema.methods.checkPassword = function (password) {
  35. return this.encryptPassword(password) === this.hashedPassword;
  36. };
  37. exports.User = mongoose.model('User',schema);
  38.  
  39. /var/www/html/chatnode/models/user.js:4
  40. var schema = new Schema({
  41. ^
  42.  
  43. ReferenceError: Schema is not defined
  44. at Object.<anonymous> (/var/www/html/chatnode/models/user.js:4:18)
  45. at Module._compile (module.js:541:32)
  46. at Object.Module._extensions..js (module.js:550:10)
  47. at Module.load (module.js:456:32)
  48. at tryModuleLoad (module.js:415:12)
  49. at Function.Module._load (module.js:407:3)
  50. at Module.require (module.js:466:17)
  51. at require (internal/module.js:20:19)
  52. at Object.<anonymous> (/var/www/html/chatnode/createDb.js:1:74)
  53. at Module._compile (module.js:541:32)
  54. at Object.Module._extensions..js (module.js:550:10)
  55. at Module.load (module.js:456:32)
  56. at tryModuleLoad (module.js:415:12)
  57. at Function.Module._load (module.js:407:3)
  58. at Function.Module.runMain (module.js:575:10)
  59. at startup (node.js:159:18)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement