From 40fa6496917931adf8c0eaceaf5deafb5f724924 Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Wed, 25 Jan 2012 12:58:37 -0700 Subject: [PATCH] fix dbwriter crash on stage_email call. move 'langContext' geration into a central location. closes #936 --- lib/wsapi.js | 11 +++++++++++ lib/wsapi/stage_email.js | 8 ++------ lib/wsapi/stage_user.js | 9 ++------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/wsapi.js b/lib/wsapi.js index 8b78e11a8..66ce3e625 100644 --- a/lib/wsapi.js +++ b/lib/wsapi.js @@ -80,6 +80,16 @@ function checkPassword(pass) { } } +function langContext(req) { + return { + lang: req.lang, + locale: req.locale, + gettext: req.gettext, + ngettext: req.ngettext, + format: req.format + }; +} + // common functions exported, for use by different api calls exports.clearAuthenticatedUser = clearAuthenticatedUser; exports.isAuthed = isAuthed; @@ -87,6 +97,7 @@ exports.bcryptPassword = bcryptPassword; exports.authenticateSession = authenticateSession; exports.checkPassword = checkPassword; exports.fowardWritesTo = undefined; +exports.langContext = langContext; exports.setup = function(options, app) { const WSAPI_PREFIX = '/wsapi/'; diff --git a/lib/wsapi/stage_email.js b/lib/wsapi/stage_email.js index 4f693d799..e26980150 100644 --- a/lib/wsapi/stage_email.js +++ b/lib/wsapi/stage_email.js @@ -32,12 +32,8 @@ exports.process = function(req, res) { try { // on failure stageEmail may throw db.stageEmail(req.session.userid, req.body.email, function(secret) { - var langContext = { - lang: req.lang, - locale: req.locale, - gettext: req.gettext, - ngettext: req.ngettext - }; + var langContext = wsapi.langContext(req); + // store the email being added in session data req.session.pendingAddition = secret; diff --git a/lib/wsapi/stage_user.js b/lib/wsapi/stage_user.js index 3c7785da1..dc5f0aef0 100644 --- a/lib/wsapi/stage_user.js +++ b/lib/wsapi/stage_user.js @@ -22,13 +22,8 @@ exports.args = ['email','site']; exports.i18n = true; exports.process = function(req, resp) { - var langContext = { - gettext: req.gettext, - lang: req.lang, - locale: req.locale, - ngettext: req.ngettext, - format: req.format - }; + var langContext = wsapi.langContext(req); + // staging a user logs you out. wsapi.clearAuthenticatedUser(req.session); -- GitLab