diff --git a/lib/wsapi.js b/lib/wsapi.js index 8b78e11a84613ed12991a8189b8cfabe8e217888..66ce3e625752223552e15d9ba5728e789e0b86ff 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 4f693d7992d5a69d2a61bbf368b9e3c608c8733e..e26980150a4a05b9a24cf7f77adc5f952ce714f8 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 3c7785da13ac586732419c6de508d67f4e4243f7..dc5f0aef04cb392a3e02de3f31de20f450bf2242 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);