Advertisement
tareknode

model.js file

Jul 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongoose = require("mongoose");
  2. mongoose.connect("mongodb://localhost/store2");
  3. var bcrypt = require("bcrypt-nodejs");
  4. var Schema = mongoose.Schema;
  5.  
  6. var userSchema = new Schema({
  7.     username: {type: String, required: true},
  8.     email: {type: String, required: true},
  9.     password: {type: String, required: true},
  10.     confirmpassword: {type: String, required: true},
  11.     passwordResetToken: {type: String, default: ""},
  12.     passwordResetExpires: {type: Date, default: Date.now},
  13.     profileimage: {type:String}
  14. });
  15. userSchema.methods.encryptPassword = function (password) {
  16.     return bcrypt.hashSync(password, bcrypt.genSaltSync(10), null);
  17. };
  18. userSchema.methods.validPassword = function (password) {
  19.     'use strict';
  20.     return bcrypt.compareSync(password, this.password);
  21. };
  22. userSchema.methods.encryptPassword = function (confirmpassword) {
  23.     "use strict";
  24.     return bcrypt.hashSync(confirmpassword, bcrypt.genSaltSync(10), null);
  25. };
  26. userSchema.methods.validPassword = function (confirmpassword) {
  27.     return bcrypt.compareSync(confirmpassword, this.confirmpassword);
  28. };
  29.  
  30. module.exports = mongoose.model("Buyer", userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement