mirror of
https://github.com/anatolykopyl/registration.git
synced 2026-03-26 12:55:25 +00:00
Added reCaptcha
This commit is contained in:
21
verify-captcha.js
Normal file
21
verify-captcha.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const request = require('request')
|
||||
|
||||
module.exports = {
|
||||
verifyCaptcha: function (req, res, cb) {
|
||||
if (!req.body['g-recaptcha-response']) {
|
||||
return res.status(401).send("Invalid captcha")
|
||||
}
|
||||
|
||||
const verificationURL = "https://www.google.com/recaptcha/api/siteverify?secret=" + process.env.SECRET_KEY + "&response=" + req.body['g-recaptcha-response'] + "&remoteip=" + req.socket.remoteAddress
|
||||
|
||||
request(verificationURL, async function(_, _, body) {
|
||||
body = JSON.parse(body)
|
||||
|
||||
if (body.success !== undefined && !body.success) {
|
||||
return res.status(401).send("Invalid captcha")
|
||||
}
|
||||
|
||||
cb()
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user