-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintenseErrorFunction.js
More file actions
49 lines (48 loc) · 1.51 KB
/
intenseErrorFunction.js
File metadata and controls
49 lines (48 loc) · 1.51 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
42
43
44
45
46
47
48
49
app.get(`/urls/:id`, (req, res) => {
let userId = req.session.email;
function findURLByKey() {
for (let key in user) {
for (let users in user[key].urlDatabase) {
if (users === userId) {
return userId;
}
}
}
return -1;
}
let result = findURLByKey();
if (userId) {
// if the url has an owner, return true
if (result === -1) {
// if (req.params.id in user[userId].urlDatabase) {
return res.status(404).send("That URL does not exist!");
// if url w/ :id does not exist:
if (userId === result) {
let templateVars = {
email: userId,
shortURL: req.params.id,
longURL: user[userId].urlDatabase[req.params.id],
urls: user[userId].urlDatabase };
return res.status(200).render("urls_show", templateVars);
// }
} else {
res.status(403).send("You do not have the necessary permissions to access this link. Login with this <a href='http://localhost:8080/login'>link</a> to access your own tiny url links.");
// if logged in user does not match the user that owns this url:
}
} else {
res.status(401).send("You must be logged in to view and create a tiny URL!");
// if user is not logged in:
}
}
});
// function findURLByKey() {
// let userId = req.session.email;
// for (let key in user) {
// for (let users in user[key].urlDatabase) {
// if (users === userId) {
// return userId;
// }
// }
// }
// return -1;
// }