Permalink
Browse files

Merge branch 'master' of git://github.com/lloyd/myfavoritebeer.org in…

…to mobile_friendly
  • Loading branch information...
shane-tomlinson committed Oct 28, 2011
2 parents 5579e71 + e87833e commit 4d4804d30c99e04087cf968a429d3a297b784e6e
Showing with 42 additions and 35 deletions.
  1. +1 −1 package.json
  2. +22 −21 server/main.js
  3. +19 −13 static/js/main.js
View
@@ -4,7 +4,7 @@
"dependencies": {
"express": "2.4.6",
"postprocess": "0.0.2",
"connect-cookie-session" : "0.0.1",
"connect-cookie-session" : "0.0.2",
"mongodb": "0.9.6-16"
},
"scripts": {
View
@@ -40,22 +40,23 @@ app.use(express.cookieParser());
// parse post bodies
app.use(express.bodyParser());
// session support using encrypted cookies
var cookieSession = sessions({
secret: COOKIE_SECRET,
key: 'myfavoritebeer_session',
cookie: {
path: '/api',
httpOnly: true,
// when you're logged in, you're logged in for an hour
maxAge: (1 * 60 * 60 * 1000),
secure: false
}
});
// session support using signed cookies
app.use(function (req, res, next) {
if (/^\/api/.test(req.url)) return cookieSession(req, res, next);
return next();
if (/^\/api/.test(req.url)) {
return sessions({
secret: COOKIE_SECRET,
key: 'myfavoritebeer_session',
cookie: {
path: '/api',
httpOnly: true,
// when you're logged in, you're logged in for an hour
maxAge: (1 * 60 * 60 * 1000),
secure: false
}
})(req, res, next);
} else {
return next();
}
});
// The next three functions contain some fancy logic to make it so
@@ -194,18 +195,18 @@ app.post("/api/set", function (req, res) {
var email = req.session.email;
if (!email) {
resp.writeHead(400, {"Content-Type": "text/plain"});
resp.write("Bad Request: you must be authenticated to get your beer");
resp.end();
res.writeHead(400, {"Content-Type": "text/plain"});
res.write("Bad Request: you must be authenticated to get your beer");
res.end();
return;
}
var beer = req.body.beer;
if (!beer) {
resp.writeHead(400, {"Content-Type": "text/plain"});
resp.write("Bad Request: a 'beer' parameter is required to set your favorite beer");
resp.end();
res.writeHead(400, {"Content-Type": "text/plain"});
res.write("Bad Request: a 'beer' parameter is required to set your favorite beer");
res.end();
return;
}
View
@@ -87,6 +87,7 @@ function logout(event) {
// which will call into browserid when clicked.
function loggedOut() {
setSessions();
$("input").val("");
$("#content .business").hide();
$('.intro').fadeIn(300);
$("header .picture").empty();
@@ -95,25 +96,30 @@ function loggedOut() {
.show().click(function() {
$("header .login").css('opacity', '0.5');
navigator.id.getVerifiedEmail(gotVerifiedEmail);
}).addClass("clickable");
}).addClass("clickable").css('opacity','1.0');
}
// a handler that is passed an assertion after the user logs in via the
// browserid dialog
function gotVerifiedEmail(assertion) {
// got an assertion, now send it up to the server for verification
$.ajax({
type: 'POST',
url: '/api/login',
data: { assertion: assertion },
success: function(res, status, xhr) {
if (res === null) loggedOut();
else loggedIn(res);
},
error: function(res, status, xhr) {
alert("login failure" + res);
}
});
if (assertion !== null) {
$.ajax({
type: 'POST',
url: '/api/login',
data: { assertion: assertion },
success: function(res, status, xhr) {
if (res === null) loggedOut();
else loggedIn(res);
},
error: function(res, status, xhr) {
alert("login failure" + res);
}
});
}
else {
loggedOut();
}
}
// For some reason, login/logout do not respond when bound using jQuery

0 comments on commit 4d4804d

Please sign in to comment.