Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replaced `jsonResponse` util usage with `res.json()`

  • Loading branch information...
commit 838d0a7545dad057327e5f09b47cf1d14fc85c8c 1 parent c501508
@tj authored
Showing with 32 additions and 33 deletions.
  1. +18 −19 browserid/lib/wsapi.js
  2. +10 −10 primary/lib/wsapi.js
  3. +4 −4 verifier/app.js
View
37 browserid/lib/wsapi.js
@@ -54,7 +54,7 @@ function setup(app) {
// get inputs from get data!
var email = url.parse(req.url, true).query['email'];
db.emailKnown(email, function(known) {
- httputils.jsonResponse(resp, known);
+ resp.json(known);
});
});
@@ -88,9 +88,7 @@ function setup(app) {
// served over an encrypted (SSL) session. guten, yah.
};
- httputils.jsonResponse(resp, true);
-
- // let's now kick out a verification email!
+ resp.json(true);
email.sendVerificationEmail(stageParams.email, stageParams.site, secret);
} catch(e) {
@@ -122,9 +120,9 @@ function setup(app) {
function(registered) {
if (registered) {
delete req.session.pendingAddition;
- httputils.jsonResponse(resp, "complete");
+ resp.json('complete');
} else {
- httputils.jsonResponse(resp, "pending");
+ resp.json('pending');
}
});
} else {
@@ -136,9 +134,9 @@ function setup(app) {
if (hash === v.hash) {
delete req.session.pendingVerification;
req.session.authenticatedUser = v.email;
- httputils.jsonResponse(resp, "complete");
+ resp.json('complete');
} else {
- httputils.jsonResponse(resp, "pending");
+ resp.json('pending');
}
});
}
@@ -156,7 +154,8 @@ function setup(app) {
if (!req.session) req.session = {};
req.session.authenticatedUser = req.body.email;
}
- httputils.jsonResponse(resp, success);
+
+ resp.json(success);
});
});
@@ -169,7 +168,7 @@ function setup(app) {
// store the email being added in session data
req.session.pendingAddition = req.body.email;
- httputils.jsonResponse(resp, true);
+ resp.json(true);
// let's now kick out a verification email!
email.sendVerificationEmail(req.body.email, req.body.site, secret);
@@ -187,7 +186,7 @@ function setup(app) {
console.log("error removing email " + email);
httputils.badRequest(resp, error.toString());
} else {
- httputils.jsonResponse(resp, true);
+ resp.json(true);
}});
});
@@ -197,13 +196,13 @@ function setup(app) {
console.log("error cancelling account : " + error.toString());
httputils.badRequest(resp, error.toString());
} else {
- httputils.jsonResponse(resp, true);
+ resp.json(true);
}});
});
app.post('/wsapi/set_key', checkAuthed, checkParams(["email", "pubkey"]), function (req, resp) {
db.addKeyToEmail(req.session.authenticatedUser, req.body.email, req.body.pubkey, function (rv) {
- httputils.jsonResponse(resp, rv);
+ resp.json(rv);
});
});
@@ -211,18 +210,18 @@ function setup(app) {
// if they're authenticated for an email address that we don't know about,
// then we should purge the stored cookie
if (!isAuthed(req)) {
- httputils.jsonResponse(resp, false);
+ resp.json(false);
} else {
db.emailKnown(req.session.authenticatedUser, function (known) {
if (!known) req.session = {}
- httputils.jsonResponse(resp, known);
+ resp.json(known);
});
}
});
app.post('/wsapi/logout', function(req,resp) {
req.session = {};
- httputils.jsonResponse(resp, "ok");
+ resp.json('ok');
});
app.post('/wsapi/sync_emails', checkAuthed, function(req,resp) {
@@ -230,7 +229,7 @@ function setup(app) {
db.getSyncResponse(req.session.authenticatedUser, emails, function(err, syncResponse) {
if (err) httputils.serverError(resp, err);
- else httputils.jsonResponse(resp, syncResponse);
+ else resp.json(syncResponse);
});
});
@@ -238,9 +237,9 @@ function setup(app) {
db.gotVerificationSecret(req.query.token, function(e) {
if (e) {
console.log("error completing the verification: " + e);
- httputils.jsonResponse(resp, false);
+ resp.json(false);
} else {
- httputils.jsonResponse(resp, true);
+ resp.json(true);
}
});
});
View
20 primary/lib/wsapi.js
@@ -47,7 +47,7 @@ exports.username_available = function(req, resp) {
var username = normalizeUsername(url.parse(req.url, true).query['username']);
logRequest("username_available", {username: username});
db.usernameKnown(username, function(known) {
- httputils.jsonResponse(resp, known);
+ resp.json(known);
});
};
@@ -66,12 +66,12 @@ exports.create_user = function(req, resp) {
db.create_user(normalized_username, getArgs["pass"], function(error) {
if (error) {
logRequest("create_user", error);
- httputils.jsonResponse(resp, undefined);
+ resp.json(undefined);
} else {
if (!req.session) req.session = {};
db.usernameToUserID(normalized_username, function(userid) {
req.session.userid = userid;
- httputils.jsonResponse(resp, {username: normalized_username, id: userid});
+ resp.json({ username: normalized_username, id: userid });
});
}
});
@@ -95,7 +95,7 @@ exports.authenticate_user = function(req, resp) {
req.session.userid = userid;
}
var rp = {username: normalized_username, status: userid != null};
- httputils.jsonResponse(resp, rp);
+ resp.json(rp);
});
};
@@ -104,7 +104,7 @@ exports.signout = function(req, resp) {
if (req.session) {
req.session.userid = undefined;// can I reference undefined safely like this?
}
- httputils.jsonResponse(resp, {});
+ resp.json({});
};
exports.add_key = function (req, resp) {
@@ -123,13 +123,13 @@ exports.add_key = function (req, resp) {
logRequest("add_key", getArgs);
db.addKeyToAccount(req.session.userid, getArgs.pubkey, function (rv) {
logRequest("add_key", "Success");
- httputils.jsonResponse(resp, rv);
+ resp.json(rv);
});
};
exports.am_authed = function(req,resp) {
logRequest("am_authed", req.session);
- httputils.jsonResponse(resp, isAuthed(req));
+ resp.json(isAuthed(req));
};
exports.current_username = function(req,resp) {
@@ -140,16 +140,16 @@ exports.current_username = function(req,resp) {
db.userIDToUsername(req.session.userid, function(username) {
if (username !== undefined) {
logRequest("current_username", username);
- httputils.jsonResponse(resp, username);
+ resp.json(username);
} else {
logRequest("current_username", "userid doesn't exist: " + req.session.userid);
req.session.userid = undefined;
- httputils.jsonResponse(resp, false);
+ resp.json(false);
}
});
} else {
logRequest("current_username", "notAuthed");
- httputils.jsonResponse(resp, false);
+ resp.json(false);
}
} catch (e) {
console.log(e);
View
8 verifier/app.js
@@ -15,7 +15,7 @@ function doVerify(req, resp, next) {
var audience = (req.query && req.query.audience) ? req.query.audience : req.body.audience;
if (!(assertion && audience))
- return httputils.jsonResponse(resp, {status:"failure", reason:"need assertion and audience"});
+ return resp.json({ status: "failure", reason: "need assertion and audience" });
// allow client side XHR to access this WSAPI, see
// https://developer.mozilla.org/en/http_access_control
@@ -42,15 +42,15 @@ function doVerify(req, resp, next) {
"valid-until" : payload["valid-until"],
issuer : payload.issuer
};
- httputils.jsonResponse(resp, result);
+ resp.json(result);
},
function(errorObj) {
- httputils.jsonResponse(resp, {status:"failure", reason:errorObj});
+ resp.json({ status: "failure", reason: errorObj });
}
);
} catch (e) {
console.log(e.stack);
- httputils.jsonResponse(resp, {status:"failure", reason:e.toString()});
+ resp.json({ status: "failure", reason: e.toString() });
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.