-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
88 lines (79 loc) · 2.5 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
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
const axios = require("axios")
const fs = require("fs")
const express = require("express")
const ngl = require("./ngl")
const app = express()
const PORT = process.env.PORT | 3000 | 5000
app.get("/", (req, res) => {
res.sendFile(`${__dirname}/index.html`)
})
app.post("/verif", async (req, res) => {
let json = JSON.parse(fs.readFileSync("users.json", "utf-8"))
let body = req.headers.body.toLowerCase().replace(/\s/gi, "")
if(/ngl\.link\/([\w_\-\.]+)/.test(body)){
body = body.match(/ngl\.link\/([\w_\-\.]+)/)[1]
}
if(json[body] != undefined){
return res.send(JSON.stringify({
ok: false,
msg: "Your account is already in our database"
}))
}
if(body.length < 5){
return res.send(JSON.stringify({
ok: false,
msg: "Please check your USERNAME"
}))
}
const verification = () => {
const alphanumeric = "abcdefghijklmnopqrstuvwxyz123456789_-"
let total = Math.floor(Math.random() * 5) + 5
let code = ""
for(let i = 0; i < total; i++){
code += alphanumeric[Math.floor(Math.random() * alphanumeric.length)]
}
return code
}
let code = verification()
json[body] = code
fs.writeFileSync("users.json", JSON.stringify(json), "utf-8")
let data = await ngl.execute(body, `Greetings, here is your verification code for NGL Random Questions: "${code}" Enjoy answering.\nFrom: Random Questionaire.`)
res.send(JSON.stringify({
ok: true,
msg: "Please check your NGL account and get the verification code."
}))
})
app.post("/done", async (req, res) => {
let json = JSON.parse(fs.readFileSync("users.json", "utf-8"))
const body = JSON.parse(req.headers.body)
if(/ngl\.link\/([\w_\-\.]+)/.test(body.usn)){
body.usn = body.usn.match(/ngl\.link\/([\w_\-\.]+)/)[1]
}
if(body.code.length < 5){
return res.send(JSON.stringify({
ok: false,
msg: "Wrong Verification"
}))
}
if(json[body.usn.toLowerCase()] == body.code.toLowerCase()){
json[body.usn.toLowerCase()] = ""
fs.writeFileSync("users.json", JSON.stringify(json), "utf-8")
let data = await ngl.execute(body.usn, `Thank you for joining, I hope you'll enjoy this.\nFrom: Random Questionaire`)
res.send(JSON.stringify({
ok: true,
msg: "You're now one of us, enjoy answering some questions from our server. Thanks."
}))
}else{
res.send(JSON.stringify({
ok: false,
msg: "Wrong Verification"
}))
}
})
app.listen(PORT, () => {
console.log("You're server is currently wordking on PORT: " + PORT)
setInterval(async () => {
// let { data } = await axios.get("https://ngl.mpoprevii.repl.co")
// console.log(data)
}, 60000 * 5)
})