-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
41 lines (35 loc) · 1.01 KB
/
Copy pathhelpers.js
File metadata and controls
41 lines (35 loc) · 1.01 KB
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
const bcrypt = require('bcrypt');
// Helper Functions
const generateRandomString = function() {
let randomString = Math.random().toString(36).substring(2, 8);
return randomString;
};
// Verify email
const verifyEmail = function(userDatabase, email) {
for (let user in userDatabase) {
if (userDatabase[user].email === email) {
return userDatabase[user];
}
}
return false;
};
// Verify password
const verifyPassword = function(userDatabase, email, password) {
const userFound = verifyEmail(userDatabase, email);
if (userFound && bcrypt.compareSync(password, userFound.password)) {
return userFound;
}
return false;
};
// Returns URL, where the userID = the logged-in user
const urlsForUser = (userDatabase, users) => {
const results = {};
for (let key in userDatabase) {
const urlObj = userDatabase[key];
if (urlObj.userID === users) {
results[key] = urlObj;
}
}
return results;
};
module.exports = { generateRandomString, verifyEmail, verifyPassword, urlsForUser };