Skip to content

Commit

Permalink
QR Verification
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowctrl committed Sep 4, 2023
1 parent ed05be1 commit 75e0d63
Show file tree
Hide file tree
Showing 30 changed files with 2,237 additions and 1,335 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mongodb_uri=mongodb+srv://hackatank:[email protected]
mongodb_collection="hackatank"
sheetsId="112d2-Xz4IFCGa6z03NaYRgO9crvLWeMnbuzKrzL0mxU"
13 changes: 0 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ const staticOptions = {
maxAge: "1d",
};

app.use(express.static(path.join(__dirname, "dist"), staticOptions));

app.get(
["/", "/about", "/set1", "/set2", "/events", "/guidelines", "/judges"],
(req, res) => {
res.status(200).sendFile(path.join(__dirname, "dist", "index.html"));
}
);

app.use((req, res) => {
res.status(404).sendFile(path.join(__dirname, "dist", "index.html"));
});

app.listen(port, () => {
console.log(`Server Running on port ${port}`);
});
57 changes: 57 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { config } from "dotenv";
config();
import { MongoClient } from "mongodb";
import express from "express";
import cors from "cors";
import sheet from "./sheetsService.mjs";
import path from "path";
import bodyParser from "body-parser";
const __dirname = path.resolve();
const app = express();
const port = 4444;
const mongo_uri = process.env.mongodb_uri;
const client = new MongoClient(mongo_uri);
client.connect();

client.on("open", () => console.log("Connected To Database"));
client.on("error", (err) => console.log("Error Occurred - MongoDB", err));
client.on("close", () => console.log("Disconnected from mongodb"));

const corsOptions = {
origin: ["https://hackatank.tech"],
};
app.use(express.json());
app.post("/api/verify", cors(corsOptions), async (req, res) => {
const requestData = req.body;

const id = parseInt(requestData.id);
const code = requestData.code;
const authBy = requestData.authemail;

const db = client.db(process.env.mongodb_collection);
const response = await db.collection("qr-details").findOne({
id,
});
if (response) {
const timestamp = new Date().toString();
const name = response.name;
const Sheetres = await sheet([[id, timestamp, name, code, authBy]]);

return res.status(200).json({ name, id, code });
} else {
return res.status(404).json({ error: "Not found", id });
}
});

app.use(express.static(path.join(__dirname, "dist")));
app.get(
["/", "/about", "/set1", "/set2", "/events", "/guidelines", "/judges"],
(req, res) => {
res.status(200).sendFile(path.join(__dirname, "dist", "index.html"));
}
);

app.use((req, res) => {
res.status(404).sendFile(path.join(__dirname, "dist", "index.html"));
});
app.listen(port, () => console.log("Server Started on port: ", port));
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
"@mui/material": "^5.14.1",
"@mui/styled-engine-sc": "^5.12.0",
"autoprefixer": "^10.4.14",
"body-parser": "^1.20.2",
"compression": "^1.7.4",
"cors": "^2.8.5",
"daisyui": "^3.2.1",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"firebase": "^10.0.0",
"firebase": "^10.3.1",
"googleapis": "^126.0.1",
"lottie-react": "^2.4.0",
"mongodb": "^6.0.0",
"ms": "^2.1.3",
"path": "^0.12.7",
"postcss": "^8.4.26",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
Binary file added public/fonts/acetone.ttf
Binary file not shown.
Binary file added public/fonts/atomed.otf
Binary file not shown.
Binary file added public/fonts/corneta.ttf
Binary file not shown.
Binary file added public/fonts/proxon.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions public/images/food.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/texture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions sheetsService.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { google } from "googleapis";
import { config } from "dotenv";
config();
const scope = ["https://www.googleapis.com/auth/spreadsheets"];
const sheetId = process.env.sheetsId;

export default async function sheet(values) {
const auth = new google.auth.GoogleAuth({
keyFile: "./sheets_creds.json",
scopes: scope[0],
});

const sheets = google.sheets({
version: "v4",
auth,
});

const data = await sheets.spreadsheets.values.append({
auth,
spreadsheetId: sheetId,
valueInputOption: "USER_ENTERED",
insertDataOption: "INSERT_ROWS",
range: "Sheet1",
resource: {
values: values,
},
});

return data.status;
}
13 changes: 13 additions & 0 deletions sheets_creds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "hackatank-1834c",
"private_key_id": "c09c7c021ec68939f0904056a432c06058470d06",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCqGlhKL24Y/hT6\nbXckMyasyFtHrrl2tLShmeNR/hg7yPCj4t4qB+jOM4/O1YQLz94H60aUQVXxrjkJ\nvs7qtHwfIHzyYTlQ5GVSkYvfIE2VSJaOqUZrqqb5yqTu/r1tKdyrQY80nwPMVx9n\n35PVqz5Iufra2i0imRgHWx1aEJH2QG16WXwb1W0teTgMIUuebJ7xHGWd0OhhJdZx\nku7Ov6+iHZex8XaVMvOC5a85YkVWMHG4QV87CupkMwtYH81vHFfW1ujiQhsmB06p\nNb3KdO8S6uS7bY18YRQlD/BNMeKhqk5YoDkWLTdSmuQ8XQfhtSZEQtiCi05yVnc5\nT4pvLGPXAgMBAAECggEAJ4JS+3gkxF1PlhMS1y+iTgODYBTvMukqA1bw+7xe+JPl\ngMtS+sQ3iJ1lS49ASlYPphs5m3nJcoca7G6LNOyS38/19X4rh+RkvFbd/AdOvdvM\nTHp4xs0uV1qAEJrOeKp+fLCPiJNemHmr6758YeaSYuX/pBGE5kJU2HCLUr4CiQVw\n3ngR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e80=\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "108756465124561266376",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/hackathon-qr%40hackatank-1834c.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}
Loading

0 comments on commit 75e0d63

Please sign in to comment.