diff --git a/src/routes/account.js b/src/routes/account.js index 89c5c225..3f8f65f1 100644 --- a/src/routes/account.js +++ b/src/routes/account.js @@ -152,37 +152,37 @@ router.get('/logout', async (_request, response) => { }); router.get('/forgot-password', async (request, response) => { - const renderData = { - input: request.cookies.input, - success_message: request.cookies.success_message, - error_message: request.cookies.error_message, - } - - response.clearCookie('input', { domain: '.pretendo.network' }); + const renderData = { + input: request.cookies.input, + success_message: request.cookies.success_message, + error_message: request.cookies.error_message, + } + + response.clearCookie('input', { domain: '.pretendo.network' }); response.render('account/forgot-password', renderData); }); router.post('/forgot-password', async (request, response) => { - const { input, 'h-captcha-response': hCaptchaResponse } = request.body; - - response.cookie('input', input, { domain: '.pretendo.network' }); - - try { - await util.forgotPassword({ - input, - hCaptchaResponse - }) + const { input, 'h-captcha-response': hCaptchaResponse } = request.body; - response.clearCookie('input', { domain: '.pretendo.network' }); + response.cookie('input', input, { domain: '.pretendo.network' }); - response.cookie('success_message', 'An email has been sent.', { domain: '.pretendo.network' }); - - response.redirect(request.redirect || '/account/forgot-password'); - } catch (error) { - response.cookie('error_message', error.message, { domain: '.pretendo.network' }); - return response.redirect('/account/forgot-password'); - } + try { + await util.forgotPassword({ + input, + hCaptchaResponse + }) + + response.clearCookie('input', { domain: '.pretendo.network' }); + + response.cookie('success_message', 'An email has been sent.', { domain: '.pretendo.network' }); + + response.redirect(request.redirect || '/account/forgot-password'); + } catch (error) { + response.cookie('error_message', error.message, { domain: '.pretendo.network' }); + return response.redirect('/account/forgot-password'); + } }); router.get('/reset-password', async (request, response) => { diff --git a/src/util.js b/src/util.js index 152f21e4..8db00209 100644 --- a/src/util.js +++ b/src/util.js @@ -131,13 +131,13 @@ async function login(username, password) { } async function forgotPassword(forgotPasswordData) { - const apiResponse = await apiPostRequest('/v1/forgot-password', {}, forgotPasswordData); - - if (apiResponse.statusCode !== 200) { - throw new Error(apiResponse.body.error); - } - - return apiResponse.body; + const apiResponse = await apiPostRequest('/v1/forgot-password', {}, forgotPasswordData); + + if (apiResponse.statusCode !== 200) { + throw new Error(apiResponse.body.error); + } + + return apiResponse.body; } async function refreshLogin(request, response) { @@ -262,24 +262,24 @@ function signDiscoursePayload(payload) { } module.exports = { - fullUrl, - getLocale, - getRawDocs, - parseDocs, - apiGetRequest, - apiPostRequest, - apiDeleteRequest, - register, - login, - forgotPassword, - refreshLogin, - getUserAccountData, - updateDiscordConnection, - removeDiscordConnection, - nintendoPasswordHash, - assignDiscordMemberSupporterRole, - assignDiscordMemberTesterRole, - removeDiscordMemberSupporterRole, - removeDiscordMemberTesterRole, - signDiscoursePayload + fullUrl, + getLocale, + getRawDocs, + parseDocs, + apiGetRequest, + apiPostRequest, + apiDeleteRequest, + register, + login, + forgotPassword, + refreshLogin, + getUserAccountData, + updateDiscordConnection, + removeDiscordConnection, + nintendoPasswordHash, + assignDiscordMemberSupporterRole, + assignDiscordMemberTesterRole, + removeDiscordMemberSupporterRole, + removeDiscordMemberTesterRole, + signDiscoursePayload };