Created
March 18, 2020 20:33
-
-
Save olegpolyakov/7864c8545833a819b224ef2cbec3f7aa to your computer and use it in GitHub Desktop.
Captcha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request'); | |
module.exports = { | |
verify(response) { | |
return new Promise((resolve, reject) => { | |
request({ | |
uri: 'https://www.google.com/recaptcha/api/siteverify', | |
method: 'POST', | |
form: { | |
secret: '6Lf22BgTAAAAACnRULGoRP6Di_PU3vLjWTubsiTT', | |
response | |
} | |
}, (error, response, body) => { | |
if (error) return reject(error); | |
let result = ''; | |
try { | |
result = JSON.parse(body); | |
} catch (error) { | |
return reject(error); | |
} | |
if (result.success) { | |
resolve(); | |
} | |
}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment