Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var crypto = require("crypto");
- var mongoose = require("../libs/mongoose");
- var schema = new Schema({
- username:{
- type:Stryng,
- unique:true,
- required:true
- },
- hashedPassword:{
- type:String,
- required:true
- },
- salt:{
- type:String,
- required:true
- },
- created:{
- type:Date,
- default:Date.now
- }
- });
- schema.metods.encryptPassword = function(password){
- return crypto.createHmac("sha1",this.salt).update(password).digest('hex');
- };
- schema.virtual('password')
- .set(function(password){
- this._plainPassword = password;
- this.salt = Math.random();
- this.hashedPassword = this.encryptPassword(password);
- })
- .get(function(){return this._plainPassword});
- shema.methods.checkPassword = function (password) {
- return this.encryptPassword(password) === this.hashedPassword;
- };
- exports.User = mongoose.model('User',schema);
- /var/www/html/chatnode/models/user.js:4
- var schema = new Schema({
- ^
- ReferenceError: Schema is not defined
- at Object.<anonymous> (/var/www/html/chatnode/models/user.js:4:18)
- at Module._compile (module.js:541:32)
- at Object.Module._extensions..js (module.js:550:10)
- at Module.load (module.js:456:32)
- at tryModuleLoad (module.js:415:12)
- at Function.Module._load (module.js:407:3)
- at Module.require (module.js:466:17)
- at require (internal/module.js:20:19)
- at Object.<anonymous> (/var/www/html/chatnode/createDb.js:1:74)
- at Module._compile (module.js:541:32)
- at Object.Module._extensions..js (module.js:550:10)
- at Module.load (module.js:456:32)
- at tryModuleLoad (module.js:415:12)
- at Function.Module._load (module.js:407:3)
- at Function.Module.runMain (module.js:575:10)
- at startup (node.js:159:18)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement