Advertisement
tareknode

sellers model

Aug 7th, 2017
89
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/store3");
  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},
  10.     confirmpassword: {type: String},
  11.     passwordResetToken: {type: String, default: ""},
  12.     passwordResetExpires: {type: Date, default: Date.now},
  13.     profileimage: {type:String},
  14.     companyname: {type: String, required: true},
  15.     role: {type: String, required: true}
  16. });
  17. userSchema.methods.encryptPassword = function (password) {
  18.     return bcrypt.hashSync(password, bcrypt.genSaltSync(10), null);
  19. };
  20. userSchema.methods.validPassword = function (password) {
  21.     'use strict';
  22.     return bcrypt.compareSync(password, this.password);
  23. };
  24. userSchema.methods.encryptPassword = function (confirmpassword) {
  25.     "use strict";
  26.     return bcrypt.hashSync(confirmpassword, bcrypt.genSaltSync(10), null);
  27. };
  28. userSchema.methods.validPassword = function (confirmpassword) {
  29.     return bcrypt.compareSync(confirmpassword, this.confirmpassword);
  30. };
  31. var Seller = module.exports = mongoose.model("Seller", userSchema, "users");
  32. module.exports.createUser = function (newUser, callback) {
  33.     newUser.save(callback);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement