Guest User

Untitled

a guest
Jan 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. const mongoose = require("mongoose");
  2. var ObjectID = require("mongodb").ObjectID;
  3. var bcrypt = require('bcrypt-nodejs');
  4.  
  5. const userSchema = mongoose.Schema({
  6. _id: String,
  7. name: String,
  8. // image: String,
  9. // bio: String,
  10. // location: String,
  11. // rating: Number,
  12. // email: String,
  13. // pw: String,
  14. // role: String,
  15. // history: String
  16. });
  17.  
  18. // generating a hash
  19. userSchema.methods.generateHash = function(password) {
  20. return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
  21. };
  22.  
  23. // checking if password is valid
  24. userSchema.methods.validPassword = function(password) {
  25. return bcrypt.compareSync(password, this.local.password);
  26. };
  27.  
  28. userSchema.methods.createNewUser = function(ame,image,bio,location,rating,
  29. email,pw,role,history){
  30. var newEntry = new userModel({
  31. _id: new ObjectID(),
  32. name: name,
  33. // image: image,
  34. // bio: bio,
  35. // location: location,
  36. // rating: rating,
  37. // email: email,
  38. // pw: pw,
  39. // role: role,
  40. // history: history
  41. });
  42.  
  43. newEntry.save(function(err){
  44. if( err ){
  45. throw err;
  46. } else{
  47. return "success";
  48. }
  49. });
  50. }
  51.  
  52. var userModel = mongoose.model('userEntry',userSchema,'users');
  53. module.exports = userModel;
Add Comment
Please, Sign In to add comment