forked from Ahe4d/spacemy.xyz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvite.php
More file actions
86 lines (83 loc) · 3.36 KB
/
Copy pathinvite.php
File metadata and controls
86 lines (83 loc) · 3.36 KB
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
<?php
require("func/conn.php");
require("func/settings.php");
requireLogin();
// https://stackoverflow.com/questions/4356289/php-random-string-generator
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Invites - spacemy.xyz</title>
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/base.css">
<style type="text/css">
table, th, td {border: 1px solid black;border-collapse: collapse;}
</style>
<?php
if (@$_POST && $_POST['create'] === "1") {
$stmt = $conn->prepare("SELECT `createdOn` FROM `invites` WHERE createdBy = ?");
$id = getID($_SESSION['user'], $conn);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$waitPeriod = false;
while($row = $result->fetch_assoc()) {
// dumb php time date stuff
$d = DateTime::createFromFormat('Y-m-d H:i:s', $row['createdOn']);
if ($d === false) {$err = "Fatal error.";goto skip;}
if (time()-86400 <= $d->getTimestamp()) {
$waitPeriod = true;
}
}
if ($waitPeriod) {$err = "Wait a while before making a new key.";goto skip;}
$stmt = $conn->prepare("INSERT INTO `invites` (`invitekey`, `createdBy`, `createdOn`, `usedBy`) VALUES (?,?,current_timestamp(),NULL)");
$key = generateRandomString(32);
$stmt->bind_param("si", $key, $id);
$stmt->execute();
}
skip:
?>
</head>
<body>
<?php
require("header.php");
$stmt = $conn->prepare("SELECT * FROM `invites` WHERE createdBy = ?");
$id = getID($_SESSION['user'], $conn);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
?>
<div class="container">
<h1>Invite keys</h1>
<?php
if (isset($err)) {echo "<span style='color:red;'>" . $err . "</span>";}
echo "<table><tr><th>Invite key</th><th>Used by</th></tr>";
while($row = $result->fetch_assoc()) {
if ($row["usedBy"]) {
$usedBy = "<a href='profile.php?id=" . $row["usedBy"] . "'>" . getName($row["usedBy"], $conn) . "</a>";
} else {
$usedBy = "Unused";
}
echo "<tr>";
echo "<td>" . $row["invitekey"] . "</td>";
echo "<td>" . $usedBy . "</td>";
echo "</tr>";
}
echo "</table>";
?><br/>
<form method="post">
<input type="hidden" name="create" value="1">
<input type="submit" value="Create new key">
</form>
</div>
</body>
</html>