Skip to content
Snippets Groups Projects
Commit 0c355ff7 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

implement 'address_info' wsapi that returns information about an email's...

implement 'address_info' wsapi that returns information about an email's current status.  who vouches for it, and if it's a secondary, is the email address known
parent cc186eae
No related branches found
No related tags found
No related merge requests found
const
db = require('../db.js'),
primary = require('../browserid/primary.js');
// return information about an email address.
// type: is this an address with 'primary' or 'secondary' support?
// if type is 'secondary':
// known: is this address known to browserid?
// if type is 'primary':
// auth: what is the url to send the user to for authentication
// prov: what is the url to embed for silent certificate (re)provisioning
exports.method = 'get';
exports.writes_db = false;
exports.authed = false;
exports.args = ['email'];
const emailRegex = /\@(.*)$/;
exports.process = function(req, resp) {
// parse out the domain from the email
var email = url.parse(req.url, true).query['email'];
var m = emailRegex.exec(email);
if (!m) {
resp.sendHeader(400);
resp.json({ "error": "invalid email address" });
return;
}
primary.checkSupport(m[1], function(err, rv) {
if (err) {
logger.warn('error checking "' + m[1] + '" for primary support: ' + err);
resp.sendHeader(500);
resp.json({ "error": "can't check email address" });
return;
}
if (rv) {
rv.type = 'primary';
resp.json(rv);
} else {
db.emailKnown(email, function(known) {
resp.json({
type: 'secondary',
known: known
});
});
}
});
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment