Skip to content

Commit

Permalink
allow relinking old contextIds by the same user
Browse files Browse the repository at this point in the history
  • Loading branch information
abramsymons committed Aug 29, 2020
1 parent e9fca07 commit b80ec55
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Binary file modified web_services/foxx/apply5.zip
Binary file not shown.
Binary file modified web_services/foxx/brightid5.zip
Binary file not shown.
22 changes: 14 additions & 8 deletions web_services/foxx/brightid5/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,6 @@ function linkContextId(id, context, contextId, timestamp) {
contextId = contextId.toLowerCase();
}

// accept link if the contextId is the last linked contextId
if (getContextIdsByUser(coll, id)[0] === contextId) {
return;
}
if (getUserByContextId(coll, contextId)) {
throw 'contextId is duplicate';
}

const links = coll.byExample({user: id}).toArray();
const recentLinks = links.filter(
link => timestamp - link.timestamp < 24*3600*1000
Expand All @@ -584,6 +576,20 @@ function linkContextId(id, context, contextId, timestamp) {
throw 'only three contextIds can be linked every 24 hours';
}

// accept link if the contextId is used by the same user before
links.forEach(link => {
if (link.contextId === contextId) {
if (timestamp > link.timestamp) {
coll.update(link, { timestamp });
}
return;
}
})

if (getUserByContextId(coll, contextId)) {
throw 'contextId is duplicate';
}

coll.insert({
user: id,
contextId,
Expand Down

0 comments on commit b80ec55

Please sign in to comment.