Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require('mongoose');
- const bcrypt = require('bcrypt-nodejs');
- // User Schema
- const UserSchema = mongoose.Schema({
- username: {
- type: String,
- index: true
- },
- password: {
- type: String
- }
- });
- const User = mongoose.model('User', UserSchema);
- module.exports = User;
- module.exports.getUserByUsername = (username, callback) => {
- const query = { username };
- User.findOne(query, callback);
- };
- module.exports.getUserById = (id, callback) => {
- User.findById(id, callback);
- };
- module.exports.comparePassword = (candidatePassword, hash, callback) => {
- bcrypt.compare(candidatePassword, hash, (err, isMatch) => {
- if (err) {
- throw err;
- }
- callback(null, isMatch);
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement