-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
193 lines (169 loc) · 8.1 KB
/
index.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
require_once "configuration.php";
session_name("DeveloperIDSession");
if(isset($_GET["swac_tokenlogin"])){
$tokenisvalid = json_decode(file_get_contents("https://tokenexchange.theskyfallen.com/?req=isvalid&token=".$_GET["swac_tokenlogin"]),true);
if($tokenisvalid["result"]["isvalid"] == "YES") {
$tokenretriaval = json_decode(file_get_contents("https://tokenexchange.theskyfallen.com/?req=retrievedata&token=".$_GET["swac_tokenlogin"]),true);
$username = $tokenretriaval["result"]["username"];
session_start();
$_SESSION["loggedin"] = true;
$_SESSION["username"] = $username;
// Redirect user to welcome page
header("location: /dashboard/");
} else {
die($tokenisvalid["result"]["isvalid"]);
}
}
// Define variables and initialize with empty values
$username = $password = $confirm_password = "";
$username_err = $password_err = $confirm_password_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"] == "register" and ALLOW_REGISTER){
// Validate username
if(empty(trim($_POST["username"]))){
$username_err = "Please enter a username.";
} else{
// Prepare a select statement
$sql = "SELECT id FROM users WHERE username = ?";
if($stmt = mysqli_prepare($loginlink, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters
$param_username = trim($_POST["username"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$username_err = "This username is already taken.<br>";
} else{
$username = trim($_POST["username"]);
}
} else{
echo "Oops! Something went wrong. Please try again later.<br>";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Validate password
if(empty(trim($_POST["password"]))){
$password_err = "Please enter a password.<br>";
} elseif(strlen(trim($_POST["password"])) < 6){
$password_err = "Password must have atleast 6 characters.<br>";
} else{
$password = trim($_POST["password"]);
}
// Validate confirm password
if(empty(trim($_POST["passwordconfirm"]))){
$confirm_password_err = "Please confirm password.<br>";
} else{
$confirm_password = trim($_POST["passwordconfirm"]);
if(empty($password_err) && ($password != $confirm_password)){
$confirm_password_err = "Password did not match.<br>";
}
}
// Check input errors before inserting in database
if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){
// Prepare an insert statement
$sql = "INSERT INTO users (username, password,verified,token) VALUES (?, ?, 'NO', '".md5(uniqid(rand(), true))."')";
if($stmt = mysqli_prepare($loginlink, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
// Set parameters
$param_username = $username;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to login page
header("location: /");
} else{
echo "Something went wrong. Please try again later. ERROR:".mysqli_stmt_error($stmt);
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Close connection
mysqli_close($loginlink);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Sign in - Skyfallen</title>
<link type="text/css" rel="stylesheet" href="css/main.css">
<script type="text/javascript" rel="script" src="js/main.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body onload="onpagloadcheck()">
<?php
if($_GET["logout"] == "true"){
?>
<script>
var http = new XMLHttpRequest();
var url = '/api/';
var params = 'action=logout';
http.open('POST', url, true);
//Send the proper header information along with the request
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
$(document).ready(function() {
$(".titleo").fadeOut(400,function (){
$(".titleo").html("Logged out successfully.");
});
$(".titleo").fadeIn(1000);
$(".titleo").fadeOut(2000,function (){
$(".titleo").html("Sign in - Skyfallen Updates Console");
});
$(".titleo").fadeIn(1000);
})
}
if(http.readyState == 4 && http.status == 403) {
alert("An unknown error occured.");
}
}
http.send(params);
</script>
<?php
}
?>
<form method="post" class="centered" id="form">
<div class="container centered text-center" id="outsider">
<div id="middle">
<div class="field text-center">
<img src="https://theskyfallen.company/wp-content/uploads/2020/07/IMG_0183.png" style="height: 100px;">
</div>
<div class="field text-center">
<h3 class="titleo"><?php if($_GET["action"] != "register"){ echo "Sign in to Skyfallen Updates Console"; } else { echo "Sign up to Skyfallen Updates Console"; } ?></h3>
</div>
<div class="field">
<input type="text" required autocomplete="off" id="username" name="username" style="border-radius: 10px 10px 0px 0px;">
<label for="username" title="Please enter your Username or E-Mail" data-title="Username or E-Mail"></label>
</div>
<?php
if($_GET["action"] == "register"){
?>
<div class="field">
<input type="password" required autocomplete="off" id="password" name="password" style="border-radius: 0px 0px 0px 0px; border-top: none;">
<label for="password" title="Please enter your password." data-title="Password"></label>
</div>
<?php
}
?>
<div class="field">
<input type="password" required autocomplete="off" id="password<?php if($_GET["action"] == "register"){ echo "confirm"; } ?>" name="password<?php if($_GET["action"] == "register"){ echo "confirm"; } ?>" style="border-radius: 0px 0px 10px 10px; border-top: none;">
<label for="password<?php if($_GET["action"] == "register"){ echo "confirm"; } ?>" title="<?php if($_GET["action"] != "register"){ echo "Please enter your password"; } else { echo "Please confirm your password."; } ?>" data-title="Password <?php if($_GET["action"] == "register"){ echo "Confirm"; } ?>"></label>
</div>
<div class="field-button">
<button type="button" style="border: none; background: transparent;" onclick="<?php if($_GET["action"] != "register"){ echo "swaploading()"; } else { echo "submitform()"; } ?>" id="submit-arrow-pwin-btn" name="submit-arrow-pwin"><img src="img/RightArrow.png" style="height: 30px;" id="submit-arrow-pwin-img" name="submit-arrow-pwin-img"> </button>
</div>
<?php echo $username_err; echo $password_err; echo $confirm_password_err;?>
</div>
</div>
</form>
<div class="footer"><p class="text-center"><?php if($_GET["action"] != "register"){ ?> Don't have an account? <a href="/?action=register">Create here <?php } else { ?> Already have a Skyfallen Developer ID? <a href="/?action=login"> Login instead. <?php } ?></a></p></div>
</body>
</html>