Created
July 20, 2021 12:15
-
-
Save danieldsf/9bf2a8ebf0c802689f48b118ad3962ba to your computer and use it in GitHub Desktop.
This file contains 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 axios = require('axios'); | |
class RecaptchaService{ | |
constructor(secret){ | |
this.secret = secret; | |
} | |
setResponse(response){ | |
this.response = response || ''; | |
return this; | |
} | |
get isValid(){ | |
return this.response; | |
} | |
async sendRequest(){ | |
try { | |
if(this.isValid){ | |
let response = await axios.post( | |
`https://www.google.com/recaptcha/api/siteverify?secret=${this.secret}&response=${this.response}`, | |
{}, | |
{ | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8" | |
}, | |
}, | |
).then(data => data.data); | |
console.log(response); | |
return response.success; | |
}else{ | |
return false; | |
} | |
} catch (error) { | |
console.log(error); | |
return false; | |
} | |
} | |
} | |
module.exports = { RecaptchaService }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment