Skip to content

Commit

Permalink
feat: enable deployment in subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
Jadeiin authored Feb 19, 2024
1 parent 902cf30 commit e2af9af
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 22 deletions.
6 changes: 4 additions & 2 deletions endpoints/user/save_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ function update_exchange_rate($db) {
if ($result) {
$cookieExpire = time() + (30 * 24 * 60 * 60);
$oldLanguage = isset($_COOKIE['language']) ? $_COOKIE['language'] : "en";
setcookie('language', $language, $cookieExpire, '/');
$root = str_replace('/endpoints/user', '', dirname($_SERVER['PHP_SELF']));
$root = $root == '' ? '/' : $root;
setcookie('language', $language, $cookieExpire, $root);
if ($username != $oldUsername) {
$_SESSION['username'] = $username;
if (isset($_COOKIE['wallos_login'])) {
Expand Down Expand Up @@ -166,4 +168,4 @@ function update_exchange_rate($db) {
echo json_encode($response);
exit();
}
?>
?>
2 changes: 1 addition & 1 deletion images/icon/site.webmanifest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"","short_name":"","icons":[{"src":"/images/icon/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/images/icon/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
{"name":"","short_name":"","icons":[{"src":"android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
4 changes: 2 additions & 2 deletions includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<header>
<div class="contain">
<div class="logo">
<a href="/">
<a href=".">
<div class="logo-image"></div>
</a>
</div>
Expand All @@ -58,7 +58,7 @@
<span id="user"><?= $username ?></span>
</button>
<div class="dropdown-content">
<a href="/"><i class="fa-solid fa-list"></i><?= translate('subscriptions', $i18n) ?></a>
<a href="."><i class="fa-solid fa-list"></i><?= translate('subscriptions', $i18n) ?></a>
<a href="stats.php"><i class="fa-solid fa-chart-simple"></i><?= translate('stats', $i18n) ?></a>
<a href="settings.php"><i class="fa-solid fa-gear"></i><?= translate('settings', $i18n) ?></a>
<a href="about.php"><i class="fa-solid fa-info-circle"></i><?= translate('about', $i18n) ?></a>
Expand Down
8 changes: 4 additions & 4 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
session_start();
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
$db->close();
header("Location: /");
header("Location: .");
exit();
}

Expand Down Expand Up @@ -47,7 +47,7 @@
$_SESSION['loggedin'] = true;
$_SESSION['main_currency'] = $main_currency;
$cookieExpire = time() + (30 * 24 * 60 * 60);
setcookie('language', $language, $cookieExpire, '/');
setcookie('language', $language, $cookieExpire);
if ($rememberMe) {
$token = bin2hex(random_bytes(32));
$addLoginTokens = "INSERT INTO login_tokens (user_id, token) VALUES (?, ?)";
Expand All @@ -57,10 +57,10 @@
$addLoginTokensStmt->execute();
$_SESSION['token'] = $token;
$cookieValue = $username . "|" . $token . "|" . $main_currency;
setcookie('wallos_login', $cookieValue, $cookieExpire, '/');
setcookie('wallos_login', $cookieValue, $cookieExpire);
}
$db->close();
header("Location: /");
header("Location: .");
exit();
} else {
$loginFailed = true;
Expand Down
4 changes: 2 additions & 2 deletions logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
$_SESSION = array();
session_destroy();
$cookieExpire = time() - 3600;
setcookie('wallos_login', '', $cookieExpire, '/');
setcookie('wallos_login', '', $cookieExpire);
$db->close();
header("Location: /");
header("Location: .");
exit();
?>
4 changes: 2 additions & 2 deletions scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function setSortOption(sortOption) {
const daysToExpire = 30;
const expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() + daysToExpire);
const cookieValue = encodeURIComponent(sortOption) + '; expires=' + expirationDate.toUTCString() + '; path=/';
const cookieValue = encodeURIComponent(sortOption) + '; expires=' + expirationDate.toUTCString();
document.cookie = 'sortOrder=' + cookieValue;
fetchSubscriptions();
toggleSortOptions();
Expand Down Expand Up @@ -314,4 +314,4 @@ document.addEventListener('DOMContentLoaded', function() {
document.querySelector('#sort-options').addEventListener('focus', function() {
isSortOptionsOpen = true;
});
});
});
4 changes: 2 additions & 2 deletions scripts/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function setCookie(name, value, days) {
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + value + expires + "; path=/";
document.cookie = name + "=" + value + expires;
}

function storeFormFieldValue(fieldId) {
Expand Down Expand Up @@ -66,4 +66,4 @@ window.onload = function () {
restoreFormFields();
removeFromStorage();
runDatabaseMigration();
};
};
14 changes: 7 additions & 7 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ function saveNotificationsButton() {
fromemail: fromEmail
};

fetch('/endpoints/notifications/save.php', {
fetch('endpoints/notifications/save.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -562,7 +562,7 @@ function testNotificationButton() {
fromemail: fromEmail
};

fetch('/endpoints/notifications/sendtestmail.php', {
fetch('endpoints/notifications/sendtestmail.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand All @@ -589,27 +589,27 @@ function switchTheme() {
darkThemeCss.disabled = !darkThemeCss.disabled;

const themeChoice = darkThemeCss.disabled ? 'light' : 'dark';
document.cookie = `theme=${themeChoice}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
document.cookie = `theme=${themeChoice}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
}

function setShowMonthlyPriceCookie() {
const showMonthlyPriceCheckbox = document.querySelector("#monthlyprice");
const value = showMonthlyPriceCheckbox.checked;
document.cookie = `showMonthlyPrice=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
document.cookie = `showMonthlyPrice=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
}

function setConvertCurrencyCookie() {
const convertCurrencyCheckbox = document.querySelector("#convertcurrency");
const value = convertCurrencyCheckbox.checked;
document.cookie = `convertCurrency=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
document.cookie = `convertCurrency=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
}

function setRemoveBackgroundCookie() {
const removeBackgroundCheckbox = document.querySelector("#removebackground");
const value = removeBackgroundCheckbox.checked;
document.cookie = `removeBackground=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
document.cookie = `removeBackground=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
}

function exportToJson() {
window.location.href = "endpoints/subscriptions/export.php";
}
}

0 comments on commit e2af9af

Please sign in to comment.