-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-user.php
112 lines (82 loc) · 3.14 KB
/
new-user.php
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
include $_SERVER['DOCUMENT_ROOT'].'/config/config.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/nfc-hex.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/is-admin.php';
echo "<style>";
include $_SERVER['DOCUMENT_ROOT'].'/css/new-user.css';
echo "</style>";
echo "<title>New User</title>";
$link = mysqli_connect($ip,$username,$password,$database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
include $_SERVER['DOCUMENT_ROOT'].'/sections/header.php';
echo "<script>";
include $_SERVER['DOCUMENT_ROOT'].'/js/display-mode.js';
echo "</script>";
echo '<body id="body" class="light-mode">';
if(isset($_POST['submit'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$UUID = $_POST['uuid'];
$adminUUID = $_POST['adminuuid'];
if(($firstname == "") or ($lastname == "")) {
errorMsg("Name field missing");
displayForm();
return;
}
if(!isAdmin($adminUUID)) {
errorMsg("Invalid Admin");
displayForm();
return;
}
if(!isset($UUID[7])){
errorMsg("Please enter a proper UUID");
} else {
# Assume someone entered the code in the back
if(is_numeric($UUID)){
$UUID = nfchex($UUID);
}
$query = "INSERT INTO elo VALUES ('$firstname', '$lastname', NULL ,1000 , 0 , 0, LOWER('$UUID'), 0, 40)";
displayForm();
$result = mysqli_query($link, $query);
if(mysqli_errno($link) == 1062){
errorMsg("UUID is already in use!");
} else if(mysqli_errno($link) == 0) {
echo "<div class='submitMsg'> <h1 class='success'>";
print_r ($firstname . ' ' . $lastname . ' registered with UUID: ' . $UUID);
echo "</h1></div>";
} else {
printf (mysqli_errno($link));
}
}
}else {
echo "";
}
displayForm();
function errorMsg($msg){
echo "<div class='submitMsg'> <h1 class='error'>$msg</h1></div>";
}
function displayForm(){
echo '<form autocomplete="off" method="post">
<a class="form-text">
First name:</a>
<input type="text" name="firstname" autofocus id="firstname"><br>
<a class="form-text">
Last name:</a>
<input type="text" name="lastname" id="lastname"><br>
<a class="form-text">
UUID:</a>
<input type="text" name="uuid" id="uuid"><br><br>
<a class="form-text">
Admin UUID:</a>
<input type="password" name="adminuuid" id="adminuuid"><br><br>
<input type="submit" value="Submit" name="submit" class="submitBtn">
</form>';
echo "<script>";
include $_SERVER['DOCUMENT_ROOT'].'/js/new-user.js';
echo "</script>";
}
?>
</body>