Skip to content

Commit

Permalink
make sure smid has owner
Browse files Browse the repository at this point in the history
  • Loading branch information
rcpeters committed Apr 21, 2017
1 parent 6f5d907 commit 96e1bc0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
17 changes: 14 additions & 3 deletions local_modules/smid-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,21 @@ SmidManger.prototype.detailsExist = function(pubKey, callback) {
})
};

SmidManger.prototype.smidExist = function(pubKey, privKey, callback) {
SmidManger.prototype.exist = function(pubKey, privKey, callback) {
this._smidCol.count({
public_key: pubKey,
private_key: privKey
private_key: privKey
}, function(err, count) {
if (err) callback(err, null);
else callback(null, count == 0 ? false : true);
})
};

SmidManger.prototype.hasOwner = function(pubKey, privKey, callback) {
this._smidCol.count({
public_key: pubKey,
private_key: privKey,
"details.owner": {$ne: undefined}
}, function(err, count) {
if (err) callback(err, null);
else callback(null, count == 0 ? false : true);
Expand All @@ -168,7 +179,7 @@ SmidManger.prototype.updateForm = function(privateKey, form, callback) {
} else {
smidManger._smidCol.findAndModify({
query: {
private_key: privateKey
private_key: privateKey,
},
update: {
$set: {
Expand Down
18 changes: 14 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ app.post(EMAIL_SMID, function(req, res) {
+ `Thanks,\n`
+ `The Share My iD Team`
};
console.log("Email to: " + data.to);
console.log("Email to: " + data.subject);
console.log("Email body: " + mailData.text);
var create_smid_authorization_uri = ooau.getAuthUrl(config.HOST + CREATE_SMID_URI, doc.private_key);
mailgunPriv.messages().send(mailData, function (error, body) {
if (error != null) {
Expand Down Expand Up @@ -267,11 +270,18 @@ app.get(ADD_ID_REDIRECT, function(req, res) { // Redeem code URL
});

app.get([COLLECTION_EDIT], function(req, res) { // Index page
smidManger.smidExist(req.params.publicKey, req.params.privateKey, function(err, bool) {
if (bool == true)
res.status(200).sendFile(index_file);
else
smidManger.exist(req.params.publicKey, req.params.privateKey, function(err, boolA) {
if (boolA == true) {
smidManger.hasOwner(req.params.publicKey, req.params.privateKey, function(err, boolB) {
if (boolB == true) {
res.status(200).sendFile(index_file);
} else {
res.redirect(ooau.getAuthUrl(config.HOST + CREATE_SMID_URI, req.params.privateKey));
}
});
} else {
res.sendFile(PAGE_404);
}
});
});

Expand Down

0 comments on commit 96e1bc0

Please sign in to comment.