-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
45 lines (39 loc) · 1.01 KB
/
helpers.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
//login checker function
const getUserByEmail = function(email, users) {
for (const user in users) {
if (users[user].email === email) {
return users[user];
}
}
return undefined;
};
//generating random string for short URL
function generatRandomString() {
let randomString = "";
let characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < 6; i++) {
randomString += characters.charAt(
Math.floor(Math.random() * characters.length)
);
}
return randomString;
}
function userURLs(id, urlDatabase) {
let userURLS = {};
for (const shortURL in urlDatabase) {
if (id === urlDatabase[shortURL].userID) {
userURLS[shortURL] = urlDatabase[shortURL];
}
}
return userURLS;
}
//checking for login user
function currentUser(cookie, userDataBase) {
for (const key in userDataBase) {
if (cookie === key) {
return true;
}
} return false;
};
module.exports = {getUserByEmail, generatRandomString, userURLs, currentUser};