-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.js
45 lines (38 loc) · 907 Bytes
/
user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const mongoose = require ('mongoose');
const bcrypt = require('bcryptjs');
const config = require ('../config/database');
//User Schema
const UserSchema = mongoose.Schema({
name : {
type: String,
},
email : {
type : String,
required : true
},
username : {
type : String,
required : true
},
password : {
type : String,
required : true
}
});
const User = module.exports = mongoose.model('User', UserSchema);
module.exports.getUserbyID = function (id, callback) {
User.findbyID(id, callback);
}
module.exports.getUserByUsername = function (username, callback) {
const query = {username: username}
User.findOne(query, callback);
}
module.exports.addUser = function (newUser, callback){
bcrypt.genSalt(10,(err,salt) => {
bcrypt.hash(newUser.password, salt, (err,hash) =>{
if (err) throw err;
newUser.password = hash;
newUser.save (callback)
});
})
}