Advertisement
tareknode

buyers model

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