Added premium verification for the Reminders feature

This commit is contained in:
ION606
2022-08-12 14:18:33 -07:00
parent 489047b084
commit 3ab442002d
7 changed files with 186 additions and 117 deletions
+52 -28
View File
@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<span id="IMPORTS">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico?raw=true" type="image/x-icon">
<script src="https://kit.fontawesome.com/728e740903.js" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet">
@@ -370,6 +370,8 @@
calSpacing.cellSpacing = 1;
calSpacing.cellPadding = 1;
}
document.getElementById('calHeader').style.display = "block";
}
</script>
@@ -389,42 +391,58 @@
//Get serverId
const id = window.localStorage.getItem('Id').toString();
var xhr2 = new XMLHttpRequest();
xhr2.open('get', 'http://www.selmerbot.com/getCal/', true);
xhr2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//Check if the user has premium
var xhrverify = new XMLHttpRequest();
xhrverify.open('post', 'http://www.selmerbot.com/verifypremium/', true);
xhrverify.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//Use the guild Id as the userId
xhr2.setRequestHeader('userId', id);
xhrverify.setRequestHeader('userId', id);
xhrverify.onloadend = (e) => {
if (xhrverify.response == "Unauthorized") {
document.getElementById("unauth").style.display = "block";
return;
}
xhr2.onloadend = (e) => {
const calList = new Map();
var xhr2 = new XMLHttpRequest();
xhr2.open('get', 'http://www.selmerbot.com/getCal/', true);
xhr2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
const res = JSON.parse(xhr2.response);
const times = res[0];
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
document.getElementById('monthName').innerText = `Editing Reminders for the Month of ${monthNames[(new Date()).getMonth()]}`;
//Use the guild Id as the userId
xhr2.setRequestHeader('userId', id);
times.forEach((time, ind) => {
const fullDate = new Date(Number(time));
const month = fullDate.getMonth();
const day = fullDate.getDate();
xhr2.onloadend = (e) => {
const calList = new Map();
//Make sure it's the right month (old ones should be removed, this is just a catch)
if (month == (new Date()).getMonth()) {
if (calList.has(day)) {
var temp = calList.get(day);
temp.push(res[1][ind]);
calList.set(day, temp);
} else {
calList.set(day, [res[1][ind]]);
const res = JSON.parse(xhr2.response);
const times = res[0];
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
document.getElementById('monthName').innerText = `Editing Reminders for the Month of ${monthNames[(new Date()).getMonth()]}`;
times.forEach((time, ind) => {
const fullDate = new Date(Number(time));
const month = fullDate.getMonth();
const day = fullDate.getDate();
//Make sure it's the right month (old ones should be removed, this is just a catch)
if (month == (new Date()).getMonth()) {
if (calList.has(day)) {
var temp = calList.get(day);
temp.push(res[1][ind]);
calList.set(day, temp);
} else {
calList.set(day, [res[1][ind]]);
}
}
}
});
});
calSetup(calList);
calSetup(calList);
}
xhr2.send();
}
xhr2.send();
xhrverify.send();
}
</script>
</head>
@@ -473,8 +491,14 @@
<caption style="caption-side: top;"></caption>
<div id="unauth" style="display: none;" class="text-center">
<h1 style="margin-bottom: 20px;">You have to be a premium subscriber to use this feature!</h1>
<h3 style="margin-bottom: 50px;">vvv GET PREMIUM NOW vvv</h3>
<a href="premium.html"><i class="fa-solid fa-crown" style="scale: 4; color: gold;" alt="PREMIUM"></i></a>
</div>
<thead>
<tr>
<tr id="calHeader" style="display: none;">
<th style="color: white; background: purple;">
Sun</th>
<th style="color: white; background: purple;">
+112 -85
View File
@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Selmer Bot Web Dashboard</title>
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico?raw=true?raw=true" type="image/x-icon">
<script src="https://kit.fontawesome.com/728e740903.js" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet">
@@ -385,102 +385,123 @@
}
}
//Load the channels
var xhr = new XMLHttpRequest();
xhr.open('get', `http://www.selmerbot.com/getChannels/`, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhr.setRequestHeader('serverNumber', serverSettings.Id);
xhr.onloadend = (e) => {
//Channel Section
const channels = JSON.parse(xhr.response);
// console.log(channels.text);
// window.localStorage.setItem('channels', (xhr.response));
for (let i = 0; i < channels.text.length; i ++) {
var channel = channels.text[i];
if (channel.name && channel.id) {
var optlog = document.createElement('option');
optlog.value = channel.id;
optlog.innerHTML = channel.name;
//I need two because if I try to append the same one, it only appends to one dorpdown
var optwelcome = document.createElement('option');
optwelcome.value = channel.id;
optwelcome.innerHTML = channel.name;
if (serverSettings.WELCOME.welcomechannel == optwelcome.value) {
optwelcome.setAttribute('selected', '');
}
if (serverSettings.LOG.logchannel == optlog.value) {
optlog.setAttribute('selected', '');
// optlog.selected = serverSettings.LOG.logchannel;
}
document.getElementById('logchanneldropdown').appendChild(optlog);
document.getElementById('welcomechanneldropdown').appendChild(optwelcome);
}
}
// document.getElementById('body').classList.replace('hide', 'show');
//Welcome section
let wc = serverSettings.WELCOME.welcomechannel || '';
let wm = serverSettings.WELCOME.welcomemessage || '';
// document.getElementById('wc').setAttribute('value', wc);
document.getElementById('wm').setAttribute('value', wm);
//Logging section ,"LOG":{"_id":"LOG","keepLogs":false,"logchannel":null,"severity":0}}
let kl = serverSettings.LOG.keepLogs || false;
let lc = serverSettings.LOG.logchannel || '';
let ls = serverSettings.LOG.severity || 0;
document.getElementById('kl').checked = kl;
// document.getElementById('lc').setAttribute('value', lc);
// document.getElementById('ls').children[ls].checked = true; //Doesn't work
}
xhr.send();
//Get serverId instead of the userId
const id = serverSettings.Id;
var xhr2 = new XMLHttpRequest();
xhr2.open('get', 'http://www.selmerbot.com/getCal/', true);
xhr2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//Check if the user has premium
var xhrverify = new XMLHttpRequest();
xhrverify.open('post', 'http://www.selmerbot.com/verifypremium/', true);
xhrverify.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhr2.setRequestHeader('userId', id);
//Use the guild Id as the userId
xhrverify.setRequestHeader('userId', id);
xhrverify.onloadend = (e) => {
console.log(xhrverify.response); //WHAT
if (xhrverify.response == "Unauthorized") {
document.getElementById("calForm").style.display = "none";
document.getElementById("unauth").style.display = "block";
return;
} else if (xhrverify.response == 'Internal Server Error') {
alert("Uh oh, an Internal Server Error has occured!\nPlease try again!");
return window.location.href = "index.html";
}
xhr2.onloadend = (e) => {
const calList = new Map();
//Load the channels
var xhr = new XMLHttpRequest();
xhr.open('get', `http://www.selmerbot.com/getChannels/`, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhr.setRequestHeader('serverNumber', id);
xhr.onloadend = (e) => {
//Channel Section
const channels = JSON.parse(xhr.response);
// console.log(channels.text);
// window.localStorage.setItem('channels', (xhr.response));
const res = JSON.parse(xhr2.response);
const times = res[0];
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
document.getElementById('monthName').innerText = `Editing Reminders for the Month of ${monthNames[(new Date()).getMonth()]}`;
for (let i = 0; i < channels.text.length; i ++) {
var channel = channels.text[i];
if (channel.name && channel.id) {
var optlog = document.createElement('option');
optlog.value = channel.id;
optlog.innerHTML = channel.name;
times.forEach((time, ind) => {
const fullDate = new Date(Number(time));
const month = fullDate.getMonth();
const day = fullDate.getDate();
//I need two because if I try to append the same one, it only appends to one dorpdown
var optwelcome = document.createElement('option');
optwelcome.value = channel.id;
optwelcome.innerHTML = channel.name;
//Make sure it's the right month (old ones should be removed, this is just a catch)
if (month == (new Date()).getMonth()) {
if (calList.has(day)) {
var temp = calList.get(day);
temp.push(res[1][ind]);
calList.set(day, temp);
} else {
calList.set(day, [res[1][ind]]);
if (serverSettings.WELCOME.welcomechannel == optwelcome.value) {
optwelcome.setAttribute('selected', '');
}
if (serverSettings.LOG.logchannel == optlog.value) {
optlog.setAttribute('selected', '');
// optlog.selected = serverSettings.LOG.logchannel;
}
document.getElementById('logchanneldropdown').appendChild(optlog);
document.getElementById('welcomechanneldropdown').appendChild(optwelcome);
}
}
});
calSetup(calList);
// document.getElementById('body').classList.replace('hide', 'show');
//Welcome section
let wc = serverSettings.WELCOME.welcomechannel || '';
let wm = serverSettings.WELCOME.welcomemessage || '';
// document.getElementById('wc').setAttribute('value', wc);
document.getElementById('wm').setAttribute('value', wm);
//Logging section ,"LOG":{"_id":"LOG","keepLogs":false,"logchannel":null,"severity":0}}
let kl = serverSettings.LOG.keepLogs || false;
let lc = serverSettings.LOG.logchannel || '';
let ls = serverSettings.LOG.severity || 0;
document.getElementById('kl').checked = kl;
// document.getElementById('lc').setAttribute('value', lc);
// document.getElementById('ls').children[ls].checked = true; //Doesn't work
}
xhr.send();
var xhr2 = new XMLHttpRequest();
xhr2.open('get', 'http://www.selmerbot.com/getCal/', true);
xhr2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhr2.setRequestHeader('userId', id);
xhr2.onloadend = (e) => {
const calList = new Map();
const res = JSON.parse(xhr2.response);
const times = res[0];
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
document.getElementById('monthName').innerText = `Editing Reminders for the Month of ${monthNames[(new Date()).getMonth()]}`;
times.forEach((time, ind) => {
const fullDate = new Date(Number(time));
const month = fullDate.getMonth();
const day = fullDate.getDate();
//Make sure it's the right month (old ones should be removed, this is just a catch)
if (month == (new Date()).getMonth()) {
if (calList.has(day)) {
var temp = calList.get(day);
temp.push(res[1][ind]);
calList.set(day, temp);
} else {
calList.set(day, [res[1][ind]]);
}
}
});
calSetup(calList);
}
xhr2.send();
}
xhr2.send();
xhrverify.send();
}
@@ -670,6 +691,12 @@
<div id="cal", class="hide wc" style="margin-top: 20px;">
<div id="unauth" class="text-center">
<h1 style="margin-bottom: 20px;">You have to be a premium subscriber to use this feature!</h1>
<h3 style="margin-bottom: 50px;">vvv GET PREMIUM NOW vvv</h3>
<a href="premium.html"><i class="fa-solid fa-crown" style="scale: 4; color: gold;" alt="PREMIUM"></i></a>
</div>
<h1 id="monthName", style="text-align: center; margin-top: 50px; margin-bottom: 25px;"></h1>
<form>
<table id="spaceId" style="background-color: lightgrey;"
@@ -696,7 +723,7 @@
appear as bold and is center aligned-->
<thead>
<tr>
<tr id="calForm">
<!-- Here we have applied inline style
to make it more attractive-->
<th style="color: white; background: purple;">
+1 -1
View File
@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Selmer Bot Web Dashboard</title>
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico?raw=true" type="image/x-icon">
<script src="https://kit.fontawesome.com/728e740903.js" crossorigin="anonymous"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
+18
View File
@@ -185,6 +185,24 @@ app.get('/.well-known/apple-developer-merchantid-domain-association', async (req
return res.sendFile('apple-developer-merchantid-domain-association', { root: '.' });
});
app.post('/verifypremium', async (req, res) => {
if (req.headers.userid) {
const id = req.headers.userid;
connection.then((client) => {
const dbo = client.db('main').collection('authorized');
dbo.findOne({id: id}).then((doc) => {
if (doc != undefined) {
res.sendStatus(200);
} else {
res.sendStatus(401);
}
}).catch((err) => {
console.error(err); return res.sendStatus(500);
})
});
}
});
app.post('/sendData', async (req, res) => {
try {
+1 -1
View File
@@ -4,7 +4,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Selmer Bot Web Dashboard</title>
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico?raw=true" type="image/x-icon">
<style>
html { width:100%; height:100%; margin:0; padding:0; }
+1 -1
View File
@@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico?raw=true" type="image/x-icon">
<script src="https://kit.fontawesome.com/728e740903.js" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet">
+1 -1
View File
@@ -7,7 +7,7 @@
<title>Selmer Bot Web Dashboard</title>
<span id="IMPORTS">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico?raw=true" type="image/x-icon">
<script src="https://kit.fontawesome.com/728e740903.js" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet">