-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
59 lines (52 loc) · 2.43 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require('express')
const path = require('path')
const bodyParser = require('body-parser')
const axios = require('axios')
const request = require('request')
const app = express()
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
const port = 3100
app.listen(port, () => {
console.log(`server is running at port: ${port}`)
})
app.get('/', (req, res) => {
res.render('index')
})
app.get('/recpatcha', (req, res) => {
res.render('recpatcha')
})
app.post('/captcha', function (req, res) {
console.log('inside capthca post method...')
if (req.body['g-recaptcha-response'] === undefined || req.body['g-recaptcha-response'] === '' || req.body['g-recaptcha-response'] === null) {
return res.json({ "responseError": "Please select captcha first" });
}
const secretKey = "6Lc2GKUUAAAAAIZImGsIx0FSLwFyCE3IZfa4yzbX";
console.log(`g-recaptcha response: ${req.body['g-recaptcha-response']}`)
const verificationURL = "https://www.google.com/recaptcha/api/siteverify?secret=" + secretKey + "&response=" + req.body['g-recaptcha-response'] + "&remoteip=" + req.connection.remoteAddress;
axios.get(verificationURL).then((result) => {
console.log(`response: ${result}`)
res.json({ 'responseSuccess': 'success' })
})
.catch(err => {
res.json({ 'responseError': 'Failed captcha verification' })
})
});
app.post('/captchaInvisible', function (req, res) {
console.log(`g-recaptcha response: ${req.body['g-recaptcha-response']} name: ${req.body['name']} token: ${req.body['token']}`)
console.log('inside captchaInvisible post method...')
if (req.body['g-recaptcha-response'] === undefined || req.body['g-recaptcha-response'] === '' || req.body['g-recaptcha-response'] === null) {
return res.json({ "responseError": "Please select captcha first" });
}
const secretKey = "6LcAFaUUAAAAAJTkiMXo6zC4oMG4aYGZq6wqrDLr";
const verificationURL = "https://www.google.com/recaptcha/api/siteverify?secret=" + secretKey + "&response=" + req.body['g-recaptcha-response'] + "&remoteip=" + req.connection.remoteAddress;
axios.get(verificationURL).then((result) => {
console.log(`response: ${result}`)
res.json({ 'responseSuccess': 'success' })
})
.catch(err => {
res.json({ 'responseError': 'Failed captcha verification' })
})
});