From 3c9eef474c40ac472afcfe052e17e2ba7a5a8891 Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Tue, 10 Jul 2012 11:03:01 -0700 Subject: [PATCH] collapse add email and reverification into a single wsapi and corresponding db call. --- ...tion.js => complete_email_confirmation.js} | 0 lib/wsapi/complete_reverify.js | 61 ------------------- 2 files changed, 61 deletions(-) rename lib/wsapi/{complete_email_addition.js => complete_email_confirmation.js} (100%) delete mode 100644 lib/wsapi/complete_reverify.js diff --git a/lib/wsapi/complete_email_addition.js b/lib/wsapi/complete_email_confirmation.js similarity index 100% rename from lib/wsapi/complete_email_addition.js rename to lib/wsapi/complete_email_confirmation.js diff --git a/lib/wsapi/complete_reverify.js b/lib/wsapi/complete_reverify.js deleted file mode 100644 index 13f6a783b..000000000 --- a/lib/wsapi/complete_reverify.js +++ /dev/null @@ -1,61 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const -db = require('../db.js'), -logger = require('../logging.js').logger, -wsapi = require('../wsapi.js'), -bcrypt = require('../bcrypt.js'), -httputils = require('../httputils.js'); - -exports.method = 'post'; -exports.writes_db = true; -exports.authed = false; -// NOTE: this API also takes a 'pass' parameter which is required -// when a user is not authenticated -exports.args = ['token']; -exports.i18n = false; - -exports.process = function(req, res) { - // in order to complete an email re-verification, one of the following must be true: - // - // 1. you must already be authenticated as the user who initiated the verification - // 2. you must provide the password of the initiator. - - db.authForVerificationSecret(req.body.token, function(err, initiator_hash, initiator_uid) { - if (err) { - logger.info("unknown verification secret: " + err); - return wsapi.databaseDown(res, err); - } - - if (req.session.userid === initiator_uid) { - postAuthentication(); - } else if (typeof req.body.pass === 'string') { - bcrypt.compare(req.body.pass, initiator_hash, function (err, success) { - if (err) { - logger.warn("max load hit, failing on auth request with 503: " + err); - return httputils.serviceUnavailable(res, "server is too busy"); - } else if (!success) { - return httputils.authRequired(res, "password mismatch"); - } else { - postAuthentication(); - } - }); - } else { - return httputils.authRequired(res, "password required"); - } - - function postAuthentication() { - db.completeReverify(req.body.token, function(e, email, uid) { - if (e) { - logger.warn("couldn't complete email verification: " + e); - wsapi.databaseDown(res, e); - } else { - wsapi.authenticateSession(req.session, uid, 'password'); - res.json({ success: true }); - } - }); - }; - }); -}; -- GitLab