mirror of
https://gitlab.com/sarlink/kyc.git
synced 2025-02-22 09:02:17 +00:00
[feat] Too many features to count....
This commit is contained in:
parent
8fe151d593
commit
01b1736857
4
.gitignore
vendored
4
.gitignore
vendored
@ -131,4 +131,6 @@ dist
|
||||
|
||||
sarlink.jpg
|
||||
|
||||
uploads/
|
||||
uploads/
|
||||
|
||||
registrations.csv
|
22
server.js
22
server.js
@ -16,7 +16,8 @@ function loadEnv() {
|
||||
},
|
||||
price: {
|
||||
normal: process.env.PRICE || "100",
|
||||
roaming: process.env.ROAMING_PRICE || "200",
|
||||
roaming: process.env.ROAMING_PRICE || "50",
|
||||
gaming: process.env.GAMING_PRICE || "100",
|
||||
currency: process.env.PRICE_CURRENCY || "MVR",
|
||||
}
|
||||
}
|
||||
@ -44,7 +45,8 @@ app.use(express.urlencoded({ extended: true }))
|
||||
|
||||
// add multer
|
||||
const multer = require("multer")
|
||||
fs.mkdirSync("uploads", { recursive: true })
|
||||
if (!fs.existsSync("uploads")) fs.mkdirSync("uploads", { recursive: true })
|
||||
if (!fs.existsSync("registrations.csv")) fs.writeFileSync("registrations.csv", "Customer Name,MAC Address,Device Name,Roaming,Gaming,Wired,Receipt\n", { encoding: "utf-8" });
|
||||
const upload = multer({
|
||||
storage: multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
@ -68,15 +70,25 @@ app.post("/register", upload.single("transfer_receipt"), (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const { customer_name, mac_address, device_name, is_roaming } = req.body
|
||||
const { customer_name, mac_address, device_name, is_roaming, is_gaming } = req.body
|
||||
const receipt = req.file;
|
||||
|
||||
if (!customer_name || !mac_address || !device_name || !receipt || !is_roaming) {
|
||||
if (!customer_name || !mac_address || !device_name || !receipt) {
|
||||
res.render("index", { branding, message: "Please fill all fields" })
|
||||
return;
|
||||
}
|
||||
|
||||
sendInfo(receipt.path, customer_name, mac_address, device_name, is_roaming)
|
||||
// save info to csv file
|
||||
const csv = `${customer_name},${mac_address},${device_name},${is_roaming === "on" ? "true" : "false"},${is_gaming === "on" ? "true" : "false"},false,${receipt.path}\n`
|
||||
fs.appendFile("registrations.csv", csv, (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
res.render("index", { branding, message: "An internal error occurred" })
|
||||
}
|
||||
});
|
||||
|
||||
// send receipt to telegram
|
||||
sendInfo(receipt.path, { customer_name, mac_address, device_name, is_roaming, is_gaming })
|
||||
.then(() => {
|
||||
res.render("success", { branding })
|
||||
})
|
||||
|
@ -2,8 +2,20 @@ const fs = require("fs")
|
||||
const FormData = require('form-data');
|
||||
const axios = require('axios').default;
|
||||
|
||||
async function sendInfo(filepath, customer_name, mac_address, device_name, roaming) {
|
||||
const caption = `Customer Name: \`${customer_name}\`\nMAC Address: \`${mac_address}\`\nDevice Name: \`${device_name}\`\nRoaming: **${roaming ? "Yes" : "No"}**`
|
||||
function kebabToTitleCase(str) {
|
||||
return str.split("_").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ")
|
||||
}
|
||||
|
||||
async function sendInfo(filepath, details) {
|
||||
// const caption = `Customer Name: \`${customer_name}\`\nMAC Address: \`${mac_address}\`\nDevice Name: \`${device_name}\`\nRoaming: **${roaming ? "Yes" : "No"}**\nGaming: **${gaming ? "Yes" : "No"}**`
|
||||
let caption = "";
|
||||
for (const key in details) {
|
||||
if (key.startsWith("is")) {
|
||||
details[key] = details[key] === "on" ? "Yes" : "No"
|
||||
}
|
||||
|
||||
caption += `${kebabToTitleCase(key)}: \`${details[key]}\`\n`
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("photo", fs.createReadStream(filepath));
|
||||
|
@ -13,20 +13,28 @@
|
||||
const customerName = document.getElementById("customer_name");
|
||||
const macAddress = document.getElementById("mac_address");
|
||||
const deviceName = document.getElementById("device_name");
|
||||
const isRoaming = document.getElementById("is_roaming");
|
||||
const isGaming = document.getElementById("is_gaming");
|
||||
|
||||
customerName.value = localStorage.getItem("customer_name") || "";
|
||||
macAddress.value = localStorage.getItem("mac_address") || "";
|
||||
deviceName.value = localStorage.getItem("device_name") || "";
|
||||
isRoaming.value = localStorage.getItem("is_roaming") === "true";
|
||||
isGaming.value = localStorage.getItem("is_gaming") === "true";
|
||||
}
|
||||
|
||||
function saveForm() {
|
||||
const customerName = document.getElementById("customer_name");
|
||||
const macAddress = document.getElementById("mac_address");
|
||||
const deviceName = document.getElementById("device_name");
|
||||
const isRoaming = document.getElementById("is_roaming");
|
||||
const isGaming = document.getElementById("is_gaming");
|
||||
|
||||
localStorage.setItem("customer_name", customerName.value);
|
||||
localStorage.setItem("mac_address", macAddress.value);
|
||||
localStorage.setItem("device_name", deviceName.value);
|
||||
localStorage.setItem("is_roaming", isRoaming.checked? "true": "false");
|
||||
localStorage.setItem("is_gaming", isGaming.checked? "true": "false");
|
||||
}
|
||||
|
||||
function clearForm() {
|
||||
@ -38,17 +46,23 @@
|
||||
document.getElementById("device_name").value = "";
|
||||
}
|
||||
|
||||
function setRoaming() {
|
||||
function setPricing() {
|
||||
const normalPrice = <%- branding.price.normal %>;
|
||||
const roamingPrice = <%- branding.price.roaming %>;
|
||||
const gamingPrice = <%- branding.price.gaming %>;
|
||||
const currency = "<%- branding.price.currency %>";
|
||||
const isRoaming = document.getElementById("is_roaming");
|
||||
const amount = document.getElementById("amount");
|
||||
const isGaming = document.getElementById("is_gaming");
|
||||
const amountLabel = document.getElementById("amount");
|
||||
let amount = normalPrice;
|
||||
if (isRoaming.checked) {
|
||||
amount.textContent = `Amount: ${roamingPrice} ${currency}`;
|
||||
} else {
|
||||
amount.textContent = `Amount: ${normalPrice} ${currency}`;
|
||||
amount += roamingPrice;
|
||||
}
|
||||
if (isGaming.checked) {
|
||||
amount += gamingPrice;
|
||||
}
|
||||
amountLabel.textContent = `Amount: ${amount} ${currency}`;
|
||||
saveForm();
|
||||
}
|
||||
|
||||
function fillDeviceName() {
|
||||
@ -346,7 +360,24 @@
|
||||
name="is_roaming"
|
||||
checked="checked"
|
||||
class="checkbox"
|
||||
oninput="setRoaming()"
|
||||
oninput="setPricing()"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="join-vertical">
|
||||
<div class="form-control">
|
||||
<label class="label cursor-pointer">
|
||||
<span class="label-text"
|
||||
>Is device going to be used for gaming?</span
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="is_gaming"
|
||||
name="is_gaming"
|
||||
class="checkbox"
|
||||
oninput="setPricing()"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
@ -457,5 +488,6 @@
|
||||
</body>
|
||||
<script>
|
||||
recoverForm();
|
||||
setPricing();
|
||||
</script>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user