Load & save & fix to login
This commit is contained in:
38
database/loadAccount.php
Normal file
38
database/loadAccount.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
require __DIR__ . '/../incl/util.php';
|
||||||
|
setJsonHeader();
|
||||||
|
checkClientDatabaseVersion();
|
||||||
|
|
||||||
|
$post = getPostData();
|
||||||
|
$token = $post['token'] ?? '';
|
||||||
|
$username = $post['username'] ?? '';
|
||||||
|
|
||||||
|
$conn = newConnection();
|
||||||
|
|
||||||
|
$stmt = $conn->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();
|
||||||
@@ -40,7 +40,7 @@ if ($currentHighScore > $user['highScore']) {
|
|||||||
$user['highScore'] = $currentHighScore;
|
$user['highScore'] = $currentHighScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = ["session" => $tokenm, "username" => $user['username'], "userid" => $id];
|
$data = ["session" => $token, "username" => $user['username'], "userid" => $id];
|
||||||
|
|
||||||
if ($loginType === "0") {
|
if ($loginType === "0") {
|
||||||
$data += [
|
$data += [
|
||||||
@@ -53,8 +53,8 @@ if ($loginType === "0") {
|
|||||||
"totalUltraBerries" => (string)$user['totalUltraBerries'],
|
"totalUltraBerries" => (string)$user['totalUltraBerries'],
|
||||||
"totalSpeedyBerries" => (string)$user['totalSpeedyBerries'],
|
"totalSpeedyBerries" => (string)$user['totalSpeedyBerries'],
|
||||||
"totalAttempts" => (string)$user['totalAttempts'],
|
"totalAttempts" => (string)$user['totalAttempts'],
|
||||||
"birdColor" => json_encode((string)$user['birdColor']),
|
"birdColor" => json_decode((string)$user['birdColor']),
|
||||||
"overlayColor" => json_encode((string)$user['overlayColor'])
|
"overlayColor" => json_decode((string)$user['overlayColor'])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
57
database/saveAccount.php
Normal file
57
database/saveAccount.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
require __DIR__ . '/../incl/util.php';
|
||||||
|
setJsonHeader();
|
||||||
|
checkClientDatabaseVersion();
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
|
||||||
|
$post = getPostData();
|
||||||
|
$token = $post['token'] ?? '';
|
||||||
|
$username = $post['username'] ?? '';
|
||||||
|
$highScore = (string)$post['highScore'] ?? '0';
|
||||||
|
$icon = (int)$post['icon'] ?? 1;
|
||||||
|
$overlay = (int)$post['overlay'] ?? 0;
|
||||||
|
$totalNormalBerries = (string)$post['totalNormalBerries'] ?? '0';
|
||||||
|
$totalPoisonBerries = (string)$post['totalPoisonBerries'] ?? '0';
|
||||||
|
$totalSlowBerries = (string)$post['totalSlowBerries'] ?? '0';
|
||||||
|
$totalUltraBerries = (string)$post['totalUltraBerries'] ?? '0';
|
||||||
|
$totalSpeedyBerries = (string)$post['totalSpeedyBerries'] ?? '0';
|
||||||
|
$totalAttempts = (string)$post['totalAttempts'] ?? '0';
|
||||||
|
$birdColor = (string)$post['birdColor'] ?? '[255,255,255]';
|
||||||
|
$overlayColor = (string)$post['overlayColor'] ?? '[255,255,255]';
|
||||||
|
|
||||||
|
$conn = newConnection();
|
||||||
|
|
||||||
|
$stmt = $conn->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();
|
||||||
Reference in New Issue
Block a user