diff --git a/database/loadAccount.php b/database/loadAccount.php new file mode 100644 index 0000000..6404ea0 --- /dev/null +++ b/database/loadAccount.php @@ -0,0 +1,38 @@ +prepare("SELECT * FROM users WHERE token = ? AND username = ?"); +$stmt->bind_param("ss", $token, $username); +$stmt->execute(); +$result = $stmt->get_result(); + +if ($result->num_rows > 0) { + $row = $result->fetch_assoc(); + echo encrypt(json_encode([ + "success" => true, + "highscore" => (string)$row['highScore'], + "icon" => (int)$row['icon'], + "overlay" => (int)$row['overlay'], + "totalNormalBerries" => (string)$row['totalNormalBerries'], + "totalPoisonBerries" => (string)$row['totalPoisonBerries'], + "totalSlowBerries" => (string)$row['totalSlowBerries'], + "totalUltraBerries" => (string)$row['totalUltraBerries'], + "totalSpeedyBerries" => (string)$row['totalSpeedyBerries'], + "totalAttempts" => (string)$row['totalAttempts'], + "birdColor" => json_decode((string)$row['birdColor']), + "overlayColor" => json_decode((string)$row['overlayColor']) + ])); +} else { + echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"])); +} + +$stmt->close(); +$conn->close(); \ No newline at end of file diff --git a/database/loginAccount.php b/database/loginAccount.php index 973a909..a4dbd45 100644 --- a/database/loginAccount.php +++ b/database/loginAccount.php @@ -40,7 +40,7 @@ if ($currentHighScore > $user['highScore']) { $user['highScore'] = $currentHighScore; } -$data = ["session" => $tokenm, "username" => $user['username'], "userid" => $id]; +$data = ["session" => $token, "username" => $user['username'], "userid" => $id]; if ($loginType === "0") { $data += [ @@ -53,8 +53,8 @@ if ($loginType === "0") { "totalUltraBerries" => (string)$user['totalUltraBerries'], "totalSpeedyBerries" => (string)$user['totalSpeedyBerries'], "totalAttempts" => (string)$user['totalAttempts'], - "birdColor" => json_encode((string)$user['birdColor']), - "overlayColor" => json_encode((string)$user['overlayColor']) + "birdColor" => json_decode((string)$user['birdColor']), + "overlayColor" => json_decode((string)$user['overlayColor']) ]; } diff --git a/database/saveAccount.php b/database/saveAccount.php new file mode 100644 index 0000000..a4b1da6 --- /dev/null +++ b/database/saveAccount.php @@ -0,0 +1,57 @@ +prepare("SELECT * FROM users WHERE token = ? AND username = ?"); +$stmt->bind_param("ss", $token, $username); +$stmt->execute(); +$result = $stmt->get_result(); + +if ($result->num_rows > 0) { + $updateStmt = $conn->prepare("UPDATE users SET highScore = ?, icon = ?, overlay = ?, totalNormalBerries = ?, totalPoisonBerries = ?, totalSlowBerries = ?, totalUltraBerries = ?, totalSpeedyBerries = ?, totalAttempts = ?, birdColor = ?, overlayColor = ? WHERE token = ? AND username = ?"); + $updateStmt->bind_param("iiiiiiiiissss", + $highScore, + $icon, + $overlay, + $totalNormalBerries, + $totalPoisonBerries, + $totalSlowBerries, + $totalUltraBerries, + $totalSpeedyBerries, + $totalAttempts, + $birdColor, + $overlayColor, + $token, + $username + ); + $updateStmt->execute(); + $updateStmt->close(); + echo encrypt(json_encode(["success" => true])); +} else { + echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"])); +} + +$stmt->close(); +$conn->close(); \ No newline at end of file