Created
September 8, 2016 11:10
-
-
Save timwis/e575a86d6631c1081e68cf43154ef98f to your computer and use it in GitHub Desktop.
couchdb view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global emit */ | |
const TOKEN_LIFESPAN = 30 // seconds | |
module.exports = { | |
_id: '_design/users', | |
views: { | |
byEmail: { | |
map: function (doc) { | |
emit(doc.metadata.email) | |
} | |
}, | |
byResetToken: { | |
map: function (doc) { | |
if (doc.metadata.resetToken && | |
((Date.now() - doc.metadata.resetToken.created) / 1000) <= TOKEN_LIFESPAN) { | |
emit(doc.metadata.resetToken.token) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment