Added options to invite codes

fixed some bugs in sanity check
This commit is contained in:
Michał Gdula 2022-11-08 11:05:09 +00:00
parent c9b81414b0
commit 2443f9b75a
7 changed files with 278 additions and 17 deletions

View file

@ -164,18 +164,77 @@
<h3>Invite Codes</h3>
<?php
$token_request = mysqli_query($conn, "SELECT * FROM tokens WHERE used = 0");
while ($token = mysqli_fetch_array($token_request)) {
?>
<button onclick='copyCode()' class='btn btn-neutral btn-code'><?php echo $token['code']; ?></button>
<script>
function copyCode() {
navigator.clipboard.writeText("<?php echo $token['code']; ?>");
sniffleAdd("Info", "Invite code has been copied!", "var(--green)", "assets/icons/clipboard-text.svg");
}
</script>
<?php
}
if (mysqli_num_rows($token_request) > 0) {
while ($token = mysqli_fetch_array($token_request)) {
?>
<div style="display: flex; flex-direction: row; gap: 0.5rem;">
<button onclick='copyCode(this)' class='btn btn-neutral btn-code'><?php echo $token['code']; ?></button>
<button onclick='regenerateCode("<?php echo $token["code"]; ?>", this)' class='btn btn-good btn-code-reg'><img src="assets/icons/arrow-clockwise.svg"></button>
<button onclick='deleteCode(<?php echo $token["id"]; ?>)' class='btn btn-bad btn-code-reg'><img src="assets/icons/cross.svg"></button>
</div>
<?php
}
} else {
echo "<div class='info-text defaultFonts' style='text-align: center !important; margin-left: 0 !important;'>
<p>No invite codes/tokens :c</p>
</div>";
}
?>
<button onclick='generateCode()' class='btn btn-good'>Generate code</button>
<script>
function copyCode(thisButton) {
var text = thisButton.innerHTML;
navigator.clipboard.writeText(text);
sniffleAdd("Info", "Invite code has been copied!", "var(--green)", "assets/icons/clipboard-text.svg");
}
function regenerateCode(code, thisButton) {
$.ajax ({
url: "app/account/token.php",
type: "POST",
data: { regenerate: code },
success: function(response) {
if (response == true) {
sniffleAdd("Woop!", "Invite code has been regenerated!", "var(--green)", "assets/icons/check.svg");
//thisButton.parentNode.remove();
} else {
sniffleAdd("Oops!", "Something went wrong!", "var(--red)", "assets/icons/cross.svg");
}
}
});
}
function generateCode() {
$.ajax ({
url: "app/account/token.php",
type: "POST",
data: { generate: true },
success: function(response) {
if (response == true) {
sniffleAdd("Woop!", "Invite code has been generated!", "var(--green)", "assets/icons/check.svg");
} else {
sniffleAdd("Oops!", "Something went wrong!", "var(--red)", "assets/icons/cross.svg");
}
}
});
}
function deleteCode(codeID, thisButton) {
$.ajax ({
url: "app/account/token.php",
type: "POST",
data: { delete: codeID },
success: function(response) {
if (response == true) {
sniffleAdd("Woop!", "Invite code has been deleted!", "var(--green)", "assets/icons/check.svg");
//thisButton.parentNode.remove();
} else {
sniffleAdd("Oops!", "Something went wrong!", "var(--red)", "assets/icons/cross.svg");
}
}
});
}
</script>
<br><h3>Admin</h3>
<div class="tabs">
@ -207,7 +266,20 @@
}
?>
<div>
<button class="btn btn-neutral" onclick="loadMore()" disabled>Load More</button>
<button class="btn btn-neutral" onclick="loadMore()">Load More</button>
<script>
function loadMore() {
$.ajax ({
url: "app/account/load.php",
type: "POST",
data: { log: true},
success: function(response) {
$("#logs").html(response);
}
});
}
</script>
</div>
</div>

35
app/account/load.php Normal file
View file

@ -0,0 +1,35 @@
<?php
include __DIR__ . "/../conn.php";
include __DIR__ . "/../app.php";
use App\Account;
use App\Diff;
$user_info = new Account();
$diff = new Diff();
if (isset($_POST['log'])) {
if ($user_info->is_admin($conn, $_SESSION['id'])) {
?>
<div class="log">
<p>ID</p> <p>User IP</p> <p>Action</p> <p>Time</p>
</div>
<?php
// Reading images from table
$logs_request = mysqli_query($conn, "SELECT * FROM logs ORDER BY id DESC");
while ($log = mysqli_fetch_array($logs_request)) {
?>
<div class="log">
<p><?php echo $log['id']; ?></p>
<p><?php echo $log['ipaddress']; ?></p>
<p><?php echo $log['action']; ?></p>
<?php
$log_time = new DateTime($log['time']);
echo "<p>".$log_time->format('Y-m-d H:i:s T')." (".$diff->time($log['time']).")</p>";
?>
</div>
<?php
}
}
}

61
app/account/token.php Normal file
View file

@ -0,0 +1,61 @@
<?php
include __DIR__ . "/../conn.php";
include __DIR__ . "/../app.php";
use App\Account;
$user_info = new Account();
if (isset($_POST['regenerate'])) {
if ($user_info->is_admin($conn, $_SESSION['id'])) {
// Prepare sql
$sql = "UPDATE tokens SET used = True WHERE code = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "s", $param_token);
$param_token = $_POST['regenerate'];
if (mysqli_stmt_execute($stmt)) {
// Generate Token
$token_array = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz';
$new_token = substr(str_shuffle($token_array), 0, 15);
if (mysqli_query($conn, "INSERT INTO tokens (code, used) VALUES('$new_token', 0)")) {
echo true;
} else {
echo false;
}
} else {
echo false;
}
}
}
if (isset($_POST['generate'])) {
if ($user_info->is_admin($conn, $_SESSION['id'])) {
// Generate Token
$token_array = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz';
$new_token = substr(str_shuffle($token_array), 0, 15);
if (mysqli_query($conn, "INSERT INTO tokens (code, used) VALUES('$new_token', 0)")) {
echo true;
} else {
echo false;
}
}
}
if (isset($_POST['delete'])) {
if ($user_info->is_admin($conn, $_SESSION['id'])) {
// Prepare sql
$sql = "UPDATE tokens SET used = True WHERE id = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "i", $param_token);
$param_token = $_POST['delete'];
if (mysqli_stmt_execute($stmt)) {
echo true;
} else {
echo false;
}
}
}

View file

@ -1,7 +1,7 @@
<?php
session_start();
include dirname(__DIR__) . "/conn.php";
include dirname(__DIR__) . "/../conn.php";
if (isset($_POST['fix'])) {
$autofix_start = microtime(true);

View file

@ -945,7 +945,7 @@ nav .btn {
color: rgba(0, 0, 0, 0);
position: relative;
}
.btn-code::after {
.btn-code::before {
content: "Hover to show code";
color: #E8E3E3;
position: absolute;
@ -956,10 +956,21 @@ nav .btn {
.btn-code:hover {
color: #E8E3E3;
}
.btn-code:hover::after {
.btn-code:hover::before {
content: "";
}
.btn-code-reg {
width: auto !important;
display: inline-block !important;
}
.btn-code-reg img {
margin: auto 2px;
width: 1.25rem;
height: 1.25rem;
display: block;
}
#sanityCheck {
padding: 0;
display: flex;
@ -1048,6 +1059,7 @@ body * {
.btn {
padding: 0.5rem;
width: 100%;
position: relative;
display: block;
box-sizing: border-box;
font-size: 16px;
@ -1057,11 +1069,43 @@ body * {
border: none;
border-radius: 3px;
transition: outline 0.1s cubic-bezier(0.19, 1, 0.22, 1);
/*
&::after {
content: "";
position: absolute;
box-sizing: border-box;
width: calc(100% + calc($border-thickness * 4));
height: calc(100% + calc($border-thickness * 4));
top: calc($border-thickness * -2);
left: calc($border-thickness * -2);
z-index: +1;
@if calc($rad - 0.5rem) > 0 {
border-radius: calc($rad - 0.5rem);
} @else {
border-radius: calc(3px * 2);
}
border: $fg $border-thickness solid;
opacity: 0;
transition: all 0.1s ease-in-out;
pointer-events: none;
}
*/
}
.btn:hover {
outline: #E8E3E3 0.2rem solid;
color: #E8E3E3;
cursor: pointer;
/*
&::after {
opacity: 1;
width: calc(100% + calc($border-thickness * 2));
height: calc(100% + calc($border-thickness * 2));
top: calc($border-thickness * -1);
left: calc($border-thickness * -1);
}
*/
}
.btn:where(input[type=file])::-webkit-file-upload-button {
margin: -0.25rem 0.5rem -0.25rem -0.25rem;

View file

@ -68,6 +68,7 @@ body {
width: 100%;
position: relative;
display: block;
box-sizing: border-box;
@ -86,11 +87,45 @@ body {
transition: outline 0.1s cubic-bezier(.19, 1, .22, 1);
/*
&::after {
content: "";
position: absolute;
box-sizing: border-box;
width: calc(100% + calc($border-thickness * 4));
height: calc(100% + calc($border-thickness * 4));
top: calc($border-thickness * -2);
left: calc($border-thickness * -2);
z-index: +1;
@if calc($rad - 0.5rem) > 0 {
border-radius: calc($rad - 0.5rem);
} @else {
border-radius: calc(3px * 2);
}
border: $fg $border-thickness solid;
opacity: 0;
transition: all 0.1s ease-in-out;
pointer-events: none;
}
*/
&:hover {
outline: $white 0.2rem solid;
color: $fg;
cursor: pointer;
/*
&::after {
opacity: 1;
width: calc(100% + calc($border-thickness * 2));
height: calc(100% + calc($border-thickness * 2));
top: calc($border-thickness * -1);
left: calc($border-thickness * -1);
}
*/
}
&:where(input[type="file"])::file-selector-button {

View file

@ -975,7 +975,7 @@
color: #00000000;
position: relative;
&::after {
&::before {
content: "Hover to show code";
color: $fg;
@ -988,12 +988,26 @@
&:hover {
color: $fg;
&::after {
&::before {
content: "";
}
}
}
.btn-code-reg {
width: auto !important;
display: inline-block !important;
img {
margin: auto 2px;
width: 1.25rem;
height: 1.25rem;
display: block;
}
}
#sanityCheck {
padding: 0;