-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
37 lines (33 loc) · 866 Bytes
/
utils.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
const User = require("./userSchema");
const bcrypt = require("bcrypt");
function parseReq(req) {
// newUserData.courses = req.body.courses;
return newUserData;
}
async function createUser(data) {
try {
await User.create({
full_name: data.full_name,
email: data.email,
password: data.password,
});
return true;
} catch (e) {
console.log("Error adding user:", e.message);
return false;
}
}
async function checkPassword(data) {
try {
const newUser = await User.findOne({ email: data.email });
if (!newUser) {
return false;
}
const isMatch = await bcrypt.compare(data.password, newUser.password);
return isMatch;
} catch (error) {
// Handle the error, e.g., log it or return false for security reasons
return false;
}
}
module.exports = { parseReq, createUser, checkPassword };