Commit 4f9b8e62 authored by Ms Kimsible's avatar Ms Kimsible
Browse files

Fix: handle errors with try catch and authorize signup when no body params

parent c9531429
......@@ -35,9 +35,11 @@ module.exports = {
}
async function verifyCaptcha (result, params, settingsManager) {
if (!params.body) return { allowed: true } // avoid PeerTube undefined body error
// mtcaptcha-response is the key that browser will generate upon form submit.
// if its blank or null means user has not selected the captcha, so return the error.
if (!params.body || !params.body["mtcaptcha-response"]) {
if (!params.body["mtcaptcha-response"]) {
return { allowed: false, errorMessage: "Captcha wasn't filled" }
}
......@@ -52,10 +54,15 @@ async function verifyCaptcha (result, params, settingsManager) {
params.body["g-recaptcha-response"]
return get(verificationUrl, function (err, res, body) {
body = JSON.parse(body)
if (body.success !== undefined && !body.success) {
return { allowed: false, errorMessage: "Wrong captcha" }
try {
if (err) throw err
body = JSON.parse(body)
if (body.success !== undefined && !body.success) {
throw new Error("Wrong captcha")
}
return result
} catch ({ message }) {
return { allowed: false, errorMessage: message }
}
return result
})
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment