-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
321 additions
and
60 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,39 @@ | ||
<?php | ||
|
||
require_once '../../includes/connect_endpoint.php'; | ||
|
||
session_start(); | ||
|
||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate('session_expired', $i18n) | ||
])); | ||
} | ||
|
||
$input = json_decode(file_get_contents('php://input'), true); | ||
if (isset($input['avatar'])) { | ||
$avatar = "images/uploads/logos/avatars/".$input['avatar']; | ||
$sql = "SELECT avatar FROM user"; | ||
$stmt = $db->prepare($sql); | ||
$result = $stmt->execute(); | ||
$userAvatar = $result->fetchArray(SQLITE3_ASSOC)['avatar']; | ||
|
||
// Check if $avatar matches the avatar in the user table | ||
if ($avatar === $userAvatar) { | ||
echo json_encode(array("success" => false)); | ||
} else { | ||
// The avatars do not match | ||
$filePath = "../../" . $avatar; | ||
if (file_exists($filePath)) { | ||
unlink($filePath); | ||
echo json_encode(array("success" => true, "message" => translate("success", $i18n))); | ||
} else { | ||
echo json_encode(array("success" => false, "message" => translate("error", $i18n))); | ||
} | ||
} | ||
} else { | ||
echo json_encode(array("success" => false, "message" => translate("error", $i18n))); | ||
} | ||
|
||
?> |
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
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
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
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
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,25 @@ | ||
<?php | ||
|
||
/** | ||
* This migration script updates the avatar field of the user table to use the new avatar path. | ||
*/ | ||
|
||
/** @noinspection PhpUndefinedVariableInspection */ | ||
$sql = "SELECT avatar FROM user"; | ||
$stmt = $db->prepare($sql); | ||
$result = $stmt->execute(); | ||
$row = $result->fetchArray(SQLITE3_ASSOC); | ||
|
||
if ($row) { | ||
$avatar = $row['avatar']; | ||
|
||
if (strlen($avatar) < 2) { | ||
$avatarFullPath = "images/avatars/" . $avatar . ".svg"; | ||
$sql = "UPDATE user SET avatar = :avatarFullPath"; | ||
$stmt = $db->prepare($sql); | ||
$stmt->bindValue(':avatarFullPath', $avatarFullPath, SQLITE3_TEXT); | ||
$stmt->execute(); | ||
} | ||
} | ||
|
||
?> |
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.