-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
190 lines (175 loc) · 5.88 KB
/
index.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
const { Database } = require("quickmongo");
const express = require("express");
const color = require("colors");
const cron = require("node-cron");
const nodemailer = require("nodemailer");
//Cache Files
const cc = require("./config.json");
//URL
const domain = "45.55.195.4";
const transporter = nodemailer.createTransport({
host: "smtp.skillssavvy.tech",
port: 587,
secure: false,
auth: {
user: "[email protected]",
pass: "e*u)s$yN0",
},
tls: {
ciphers: "SSLv3",
rejectUnauthorized: false,
},
});
const db = new Database(cc.mongodb);
db.connect();
db.on("ready", async () => {
console.log(color.bold.red("=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="));
console.log(
color.bold.cyan(`---------------------------------------------------`)
);
console.log(color.bold.yellow(`Database Connected`));
console.log(
color.bold.cyan(`---------------------------------------------------`)
);
console.log(color.bold.red("=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="));
//Cron-Job
cron.schedule("37 3 * * *", async () => {
const getMails = await db.getArray("mail_slot_1");
console.log(getMails);
getMails.forEach(async (mail) => {
const name = await db.get(`slot_1_${mail}.name`);
const game = await db.get(`slot_1_${mail}.game`);
const message = `Hi ${name}\nYou have registered for match the details are as follows :
12 PM to 1 PM
Game's name - ${game}
Gamer's name - ${name}`;
await sendEmail(mail, "Remainder", message);
});
});
cron.schedule("12 3 * * *", async () => {
const getMails = await db.getArray("mail_slot_2");
console.log(getMails);
getMails.forEach(async (mail) => {
const name = await db.get(`slot_2_${mail}.name`);
const game = await db.get(`slot_2_${mail}.game`);
const message = `Hi ${name}\nYou have registered for match the details are as follows :
12 PM to 1 PM
Game's name - ${game}
Gamer's name - ${name}`;
await sendEmail(mail, "Remainder", message);
});
});
cron.schedule("12 3 * * *", async () => {
const getMails = await db.getArray("mail_slot_3");
console.log(getMails);
getMails.forEach(async (mail) => {
const name = await db.get(`slot_3_${mail}.name`);
const game = await db.get(`slot_3_${mail}.game`);
const message = `Hi ${name}\nYou have registered for match the details are as follows :
12 PM to 1 PM
Game's name - ${game}
Gamer's name - ${name}`;
await sendEmail(mail, "Remainder", message);
});
});
cron.schedule("12 3 * * *", async () => {
const getMails = await db.getArray("mail_slot_4");
console.log(getMails);
getMails.forEach(async (mail) => {
const name = await db.get(`slot_4_${mail}.name`);
const game = await db.get(`slot_4_${mail}.game`);
const message = `Hi ${name}\nYou have registered for match the details are as follows :
12 PM to 1 PM
Game's name - ${game}
Gamer's name - ${name}`;
await sendEmail(mail, "Remainder", message);
});
});
});
const app = new express();
app.use(express.json());
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
res.header("Access-Control-Allow-Headers", "Content-Type");
next();
});
//Login Form ------------------->>>>>>>>>>>>>>>>>>
port = 3000;
app.get("/api/login/:email/:password", async (req, res) => {
console.warn(req.params.email);
console.warn(req.params.password);
const email = req.params.email;
const password = req.params.password;
try {
const emails = await db.getArray("emails");
if (emails.includes(email)) {
const pass = await db.get(`all-mail.${email}.pass`);
if (password == pass) {
res.json({ success: true, message: "Login Successful" });
} else {
res.json({ success: false, message: "Incorrect Password" });
}
} else {
res.json({ success: false, message: "Invalid Email or Password" });
}
} catch (error) {
console.error(error);
res.status(500).json({ error: "Internal Server Error" });
}
});
//Sign UP------------------->>>>>>>>>>>>>>>>>>>
app.get("/api/continue/:email/:password", async (req, res) => {
console.warn(req.params.email);
console.warn(req.params.password);
const email = req.params.email;
const pass = req.params.password;
try {
const emails = await db.getArray("emails");
console.log(emails);
if (emails.includes(email)) {
res.json({ success: false, message: "This Email is Already Used" });
} else {
await db.push(`emails`, email);
await db.set(`all-mail.${email}.pass`, pass);
res.json({ success: true, message: "Registration Successfull" });
}
} catch (error) {
console.error(error);
res.status(500).json({ error: "Internal Server Error" });
}
});
//register---------------->>>>>>>>>>>>>>>>>>>>>>
app.get("/api/regis/:slot/:game/:mail/:name", async (req, res) => {
console.warn(req.params.name);
console.warn(req.params.mail);
console.warn(req.params.slot);
console.warn(req.params.game);
const mail = req.params.mail;
const name = req.params.name;
const slots = req.params.slot;
const game = req.params.game;
await db.push(`mail_${slots}`, mail);
await db.set(`${slots}_${mail}.name`, name);
await db.set(`${slots}_${mail}.game`, game);
res.json({ success: true, message: "Successfull" });
});
app.listen(port, () => {
console.log(`Server is running on http://${domain}:${port}`);
});
async function sendEmail(mail, subject, text) {
console.log(mail, subject, text);
const mailOptions = {
from: `"Gamics Esports" <[email protected]>`,
to: mail,
subject: subject,
text: text,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error(error);
} else {
console.log(`Email sent: ${mail} | ${info.response}`);
}
});
}