-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new features like settings for account management
- Loading branch information
1 parent
a61333f
commit bc8474e
Showing
13 changed files
with
338 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
include "../config.php"; | ||
|
||
$user_id = $_GET['user_id']; | ||
|
||
$query = $conn->prepare("DELETE FROM users WHERE user_id = (?)"); | ||
$query->bind_param("s", $user_id); | ||
$query->execute(); | ||
|
||
if ($query){ | ||
echo 1; | ||
} else { | ||
echo 0; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
include "../config.php"; | ||
|
||
$user_id = $_GET['user_id']; | ||
|
||
$query = $conn->prepare("SELECT * FROM users WHERE user_id = (?)"); | ||
$query->bind_param("s", $user_id); | ||
$query->execute(); | ||
|
||
$result = $query->get_result(); | ||
|
||
$accountData = array(); | ||
|
||
while ($row = $result->fetch_assoc()) { | ||
$accountItem = array( | ||
'user_id' => $row['user_id'], | ||
'username' => $row['username'], | ||
'email' => $row['email'] | ||
|
||
); | ||
$accountData[] = $accountItem; | ||
} | ||
|
||
// Convert the data to JSON and send it as the response | ||
header('Content-Type: application/json'); | ||
echo json_encode($accountData); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
include "../config.php"; | ||
|
||
$new_username = $_POST['new_username']; | ||
$new_email = $_POST['new_email']; | ||
$new_psk = $_POST['new_psk']; | ||
|
||
$user_id = $_GET['user_id']; | ||
|
||
if (!empty($new_username) || !empty($new_email)) { | ||
// Check if the new username or email is not already taken | ||
$username_exists = false; | ||
$email_exists = false; | ||
|
||
|
||
if (!empty($new_username)) { | ||
$query = $conn->prepare("SELECT * FROM users WHERE username = ?"); | ||
$query->bind_param("s", $new_username); | ||
$query->execute(); | ||
$result_username = $query->get_result(); | ||
$num_username = $result_username->num_rows; | ||
$username_exists = ($num_username > 0); | ||
} | ||
|
||
if (!empty($new_email)) { | ||
$query = $conn->prepare("SELECT * FROM users WHERE email = ?"); | ||
$query->bind_param("s", $new_email); | ||
$query->execute(); | ||
$result_email = $query->get_result(); | ||
$num_email = $result_email->num_rows; | ||
$email_exists = ($num_email > 0); | ||
} | ||
|
||
if ($username_exists && $email_exists) { | ||
if (!empty($new_psk)) { | ||
$hash_psk = password_hash($new_psk, PASSWORD_DEFAULT); | ||
|
||
$query = $conn->prepare("UPDATE users SET username = ?, email = ?, psk = ? WHERE user_id = ?"); | ||
$query->bind_param("ssss", $new_username, $new_email, $hash_psk, $user_id); | ||
|
||
if ($query->execute()) { | ||
echo 1; // Success | ||
} else { | ||
echo 0; // Failure | ||
} | ||
} else { | ||
echo 2;//for username or email exist | ||
} | ||
|
||
|
||
|
||
|
||
} else if ($username_exists) { | ||
if (!$email_exists) { | ||
$query = $conn->prepare("UPDATE users SET email = ? WHERE user_id = ?"); | ||
$query->bind_param("ss", $new_email, $user_id); | ||
|
||
|
||
} | ||
|
||
if (!empty($new_psk)) { | ||
$hash_psk = password_hash($new_psk, PASSWORD_DEFAULT); | ||
|
||
$query = $conn->prepare("UPDATE users SET username = ?, email = ?, psk = ? WHERE user_id = ?"); | ||
$query->bind_param("ssss", $new_username, $new_email, $hash_psk, $user_id); | ||
} | ||
|
||
if ($query->execute()) { | ||
echo 1; // Success | ||
} else { | ||
echo 0; // Failure | ||
} | ||
|
||
} else if ($email_exists) { | ||
if (!$username_exists) { | ||
$query = $conn->prepare("UPDATE users SET username = ? WHERE user_id = ?"); | ||
$query->bind_param("ss", $new_username, $user_id); | ||
|
||
|
||
} | ||
|
||
if (!empty($new_psk)) { | ||
$hash_psk = password_hash($new_psk, PASSWORD_DEFAULT); | ||
|
||
$query = $conn->prepare("UPDATE users SET username = ?, email = ?, psk = ? WHERE user_id = ?"); | ||
$query->bind_param("ssss", $new_username, $new_email, $hash_psk, $user_id); | ||
} | ||
|
||
if ($query->execute()) { | ||
echo 1; // Success | ||
} else { | ||
echo 0; // Failure | ||
} | ||
} else { | ||
if (!empty($new_psk)) { | ||
$hash_psk = password_hash($new_psk, PASSWORD_DEFAULT); | ||
|
||
$query = $conn->prepare("UPDATE users SET username = ?, email = ?, psk = ? WHERE user_id = ?"); | ||
$query->bind_param("ssss", $new_username, $new_email, $hash_psk, $user_id); | ||
} else { | ||
$query = $conn->prepare("UPDATE users SET username = ?, email = ? WHERE user_id = ?"); | ||
$query->bind_param("sss", $new_username, $new_email, $user_id); | ||
} | ||
|
||
if ($query->execute()) { | ||
echo 1; // Success | ||
} else { | ||
echo 0; // Failure | ||
} | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.