Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
128 lines (102 loc) · 2.8 KB
/
Copy pathindex.js
File metadata and controls
128 lines (102 loc) · 2.8 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require('dotenv').config()
// FORMURL = https://docs.google.com/forms/d/e/****/formResponse?usp=pp_url your form url
// RECAPTCHAKEY = 6***s from https://www.google.com/recaptcha/admin
const express = require("express")
const app = express()
const bodyParser = require("body-parser")
const axios = require("axios")
var cors = require("cors")
app.use(cors())
app.use(bodyParser.json())
app.get("/", (req, res) => {
res.json({
port: PORT,
info: "Compec DataCamp API http://datacamp.boun.edu.tr/",
developer: "EminDeniz99"
})
})
app.get("/datacampkayit", (req, res) => {
console.log(req.body)
let r = req.query
var formLink = process.env.FORMURL
// "https://docs.google.com/forms/d/e/***Unique-Form-Parameter***/formResponse?usp=pp_url"
var recaptchaKey = ""
// console.log(formLink);
// parse the request and get recaptcha to check, also forward inputs to google forms link
Object.keys(r).map(item => {
// console.log(item,r[item])
if (item == "recaptcha") {
recaptchaKey = r[item]
} else {
formLink += "&" + item + "=" + r[item]
}
// console.log(formLink);
})
if (
recaptchaKey == undefined ||
recaptchaKey == null ||
recaptchaKey == ""
) {
console.log("bos recap")
return res.json({
responseCode: "ERROR",
responseDesc: "Lütfen Captcha'yı doldurunuz."
})
} else {
var secretKey = process.env.RECAPTCHAKEY
// req.connection.remoteAddress will provide IP address of connected user.
var verificationUrl =
"https://www.google.com/recaptcha/api/siteverify?secret=" +
secretKey +
"&response=" +
recaptchaKey +
"&remoteip=" +
req.connection.remoteAddress
// Hitting GET request to the URL, Google will respond with success or error scenario.
console.log("anahtar", recaptchaKey)
axios.get(encodeURI(verificationUrl)).then(response => {
console.log("log rsdata,", response.data)
if (response.data.success !== undefined && !response.data.success) {
return res.json({
responseCode: "ERROR",
responseDesc: "Lütfen tekrar Captcha'yı doldurunuz"
})
} else {
axios
.get(encodeURI(formLink))
.then(response => {
// console.log(response.data.url);
// console.log(response.data.explanation);
})
.catch(error => {
console.log(error)
})
console.log(formLink)
return res.json({
responseCode: "OK",
responseDesc: "Basarili"
})
}
// console.log(response);
})
}
// "&entry.1140033869="+"ad%C4%B1n"+
// "&entry.1139239116=soyad%C4%B1n"+
// "&submit=Submit"
})
const PORT = normalizePort(process.env.PORT || "4000")
function normalizePort(val) {
var port = parseInt(val, 10)
if (isNaN(port)) {
// named pipe
return val
}
if (port >= 0) {
// port number
return port
}
return false
}
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
})