Work on 2FA/OTP email system

* Web routes/handler/etc. mostly functional
* Can now enable -> follow link -> submit -> capture form
* Clean up code
This commit is contained in:
Bryan Ashby 2019-06-12 21:57:45 -06:00
parent fa3e3e5802
commit 3efea3de9a
No known key found for this signature in database
GPG key ID: B49EB437951D2542
8 changed files with 273 additions and 85 deletions

View file

@ -25,17 +25,17 @@ exports.WellKnownTokenTypes = {
AuthFactor2OTPRegister : 'auth_factor2_otp_register',
};
function createToken(userId, tokenType, cb) {
function createToken(userId, tokenType, options = { bits : 128 }, cb) {
async.waterfall(
[
(callback) => {
return crypto.randomBytes(256, callback);
return crypto.randomBytes(options.bits, callback);
},
(token, callback) => {
token = token.toString('hex');
UserDb.run(
`INSERT INTO user_temporary_token (user_id, token, token_type, timestamp)
`INSERT OR REPLACE INTO user_temporary_token (user_id, token, token_type, timestamp)
VALUES (?, ?, ?, ?);`,
[ userId, token, tokenType, getISOTimestampString() ],
err => {