Require auth for read-only requests too

This commit is contained in:
Calvin Montgomery 2014-08-04 18:01:57 -07:00
parent 032dede66d
commit d94c596063
1 changed files with 55 additions and 32 deletions

View File

@ -26,9 +26,18 @@ function handleAccountEditPage(req, res) {
if (req.cookies.auth) { if (req.cookies.auth) {
loginName = req.cookies.auth.split(":")[0]; loginName = req.cookies.auth.split(":")[0];
} }
sendJade(res, "account-edit", {
loggedIn: loginName !== false, db.users.verifyAuth(req.cookies.auth, function (err, user) {
loginName: loginName if (err) {
return sendJade(res, "account-edit", {
loggedIn: false
});
}
sendJade(res, "account-edit", {
loggedIn: loginName !== false,
loginName: loginName
});
}); });
} }
@ -185,11 +194,19 @@ function handleAccountChannelPage(req, res) {
} }
if (loginName) { if (loginName) {
db.channels.listUserChannels(loginName, function (err, channels) { db.users.verifyAuth(req.cookies.auth, function (err, user) {
sendJade(res, "account-channels", { if (err) {
loggedIn: true, return sendJade(res, "account-channels", {
loginName: loginName, loggedIn: false
channels: channels });
}
db.channels.listUserChannels(loginName, function (err, channels) {
sendJade(res, "account-channels", {
loggedIn: true,
loginName: loginName,
channels: channels
});
}); });
}); });
} else { } else {
@ -415,37 +432,43 @@ function handleAccountProfilePage(req, res) {
logRequest(req); logRequest(req);
var loginName = false; var loginName = false;
if (req.cookies.auth) { if (!req.cookies.auth) {
loginName = req.cookies.auth.split(":")[0]; return sendJade(res, "account-profile", {
} else {
sendJade(res, "account-profile", {
loggedIn: false, loggedIn: false,
profileImage: "", profileImage: "",
profileText: "" profileText: ""
}); });
return; } else {
} loginName = req.cookies.auth.split(":")[0];
db.users.verifyAuth(req.cookies.auth, function (err, user) {
if (err) {
return sendJade(res, "account-profile", {
loggedIn: false
});
}
db.users.getProfile(loginName, function (err, profile) { db.users.getProfile(loginName, function (err, profile) {
if (err) { if (err) {
sendJade(res, "account-profile", { sendJade(res, "account-profile", {
loggedIn: true, loggedIn: true,
loginName: loginName, loginName: loginName,
profileError: err, profileError: err,
profileImage: "", profileImage: "",
profileText: "" profileText: ""
});
return;
}
sendJade(res, "account-profile", {
loggedIn: true,
loginName: loginName,
profileImage: profile.image,
profileText: profile.text,
profileError: false
});
}); });
return;
}
sendJade(res, "account-profile", {
loggedIn: true,
loginName: loginName,
profileImage: profile.image,
profileText: profile.text,
profileError: false
}); });
}); }
} }
/** /**