Advertisement
Guest User

Untitled

a guest
May 24th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. const mongoose = require('mongoose');
  2.  
  3. const bcrypt = require('bcrypt-nodejs');
  4.  
  5. // User Schema
  6. const UserSchema = mongoose.Schema({
  7. username: {
  8. type: String,
  9. index: true
  10. },
  11. password: {
  12. type: String
  13. }
  14. });
  15.  
  16. const User = mongoose.model('User', UserSchema);
  17. module.exports = User;
  18.  
  19. module.exports.getUserByUsername = (username, callback) => {
  20. const query = { username };
  21. User.findOne(query, callback);
  22. };
  23.  
  24. module.exports.getUserById = (id, callback) => {
  25. User.findById(id, callback);
  26. };
  27.  
  28. module.exports.comparePassword = (candidatePassword, hash, callback) => {
  29. bcrypt.compare(candidatePassword, hash, (err, isMatch) => {
  30. if (err) {
  31. throw err;
  32. }
  33. callback(null, isMatch);
  34. });
  35. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement