Skip to content

Commit

Permalink
Allow redirection & fix registration bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
katniny committed Oct 15, 2024
1 parent 63e859c commit 28a7d2e
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
17 changes: 17 additions & 0 deletions assets/css/mainSite.css
Original file line number Diff line number Diff line change
Expand Up @@ -3114,4 +3114,21 @@ small {
max-width: 100%;
border-radius: 15px;
height: 200px;
}

/* registration badge */
.formBox .badge {
background: var(--main-color);
padding: 2px 8px;
border-radius: 12px;
font-size: 0.8em;
margin-left: 5px;
color: var(--hovered-button-text);
display: block;
margin-bottom: 5px;
margin-top: 10px;
}

.formBox .badge i {
color: var(--hovered-button-text);
}
20 changes: 10 additions & 10 deletions assets/js/pageLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ firebase.auth().onAuthStateChanged((user) => {
const getTheme = snapshot.val();

// Set zoom level
if (getTheme.fontSizePref) {
if (getTheme && getTheme.fontSizePref) {
if (getTheme.fontSizePref === "normal") {
document.documentElement.style.setProperty('--zoom-level', '1');
} else if (getTheme.fontSizePref === "large") {
document.documentElement.style.setProperty('--zoom-level', '1.07');
}
}

if (getTheme.theme === "Dark" || getTheme.theme === undefined) {
if (getTheme && getTheme.theme === "Dark" || getTheme && getTheme.theme === undefined) {
// Dark theme by default
} else if (getTheme.theme === "Light") {
} else if (getTheme && getTheme.theme === "Light") {
document.documentElement.style.setProperty('--background', '#f5f5f5');
document.documentElement.style.setProperty('--main-color', '#dd6075');
document.documentElement.style.setProperty('--main-color-darker', '#b44d5d');
Expand Down Expand Up @@ -129,7 +129,7 @@ firebase.auth().onAuthStateChanged((user) => {
if (currentMonth === 6 && getTheme.showPrideFlag === "Yes" || currentMonth === 6 && getTheme.showPrideFlag === undefined) {
document.getElementById("transsocialHeaderLogo").src = "/assets/imgs/PrideHeaderLogo.png";
}
} else if (getTheme.theme === "Mint (Light)") {
} else if (getTheme && getTheme.theme === "Mint (Light)") {
document.documentElement.style.setProperty('--background', '#f0f8ff');
document.documentElement.style.setProperty('--main-color', '#9be7c4');
document.documentElement.style.setProperty('--main-color-darker', '#62c198');
Expand Down Expand Up @@ -164,7 +164,7 @@ firebase.auth().onAuthStateChanged((user) => {
} else {
document.getElementById("transsocialHeaderLogo").src = "/assets/imgs/MintLightThemeLogo.png";
}
} else if (getTheme.theme === "Mint (Dark)") {
} else if (getTheme && getTheme.theme === "Mint (Dark)") {
document.documentElement.style.setProperty('--background', '#18282d');
document.documentElement.style.setProperty('--main-color', '#add8d0');
document.documentElement.style.setProperty('--main-color-darker', '#8cc0b2');
Expand Down Expand Up @@ -198,7 +198,7 @@ firebase.auth().onAuthStateChanged((user) => {
} else {
document.getElementById("transsocialHeaderLogo").src = "/assets/imgs/MintDarkThemeLogo.png";
}
} else if (getTheme.theme === "High Contrast") {
} else if (getTheme && getTheme.theme === "High Contrast") {
document.documentElement.style.setProperty('--background', 'black');
document.documentElement.style.setProperty('--main-color', 'yellow');
document.documentElement.style.setProperty('--main-color-darker', '#cccc00');
Expand Down Expand Up @@ -232,7 +232,7 @@ firebase.auth().onAuthStateChanged((user) => {
} else {
document.getElementById("transsocialHeaderLogo").src = "/assets/imgs/HighContrastThemeLogo.png";
}
} else if (getTheme.theme === "TransSocial Classic") {
} else if (getTheme && getTheme.theme === "TransSocial Classic") {
document.documentElement.style.setProperty('--background', '#ffb2a8');
document.documentElement.style.setProperty('--main-color', '#ffb2a8');
document.documentElement.style.setProperty('--main-color-darker', '#f0cfb6');
Expand Down Expand Up @@ -266,7 +266,7 @@ firebase.auth().onAuthStateChanged((user) => {
} else {
document.getElementById("transsocialHeaderLogo").src = "/assets/imgs/TransSocialClassicThemeLogo.png";
}
} else if (getTheme.theme === "Midnight Purple") {
} else if (getTheme && getTheme.theme === "Midnight Purple") {
document.documentElement.style.setProperty('--background', '#221e2b');
document.documentElement.style.setProperty('--main-color', '#957DAD');
document.documentElement.style.setProperty('--main-color-darker', '#786491');
Expand Down Expand Up @@ -300,7 +300,7 @@ firebase.auth().onAuthStateChanged((user) => {
} else {
document.getElementById("transsocialHeaderLogo").src = "/assets/imgs/MidnightPurpleThemeLogo.png";
}
} else if (getTheme.theme === "Darker") {
} else if (getTheme && getTheme.theme === "Darker") {
document.documentElement.style.setProperty('--background', '#171717');
document.documentElement.style.setProperty('--main-color', '#ff869a');
document.documentElement.style.setProperty('--main-color-darker', '#e1788a');
Expand Down Expand Up @@ -328,7 +328,7 @@ firebase.auth().onAuthStateChanged((user) => {
document.documentElement.style.setProperty('--reply-background', '#282828');
document.documentElement.style.setProperty('--reply-hovered-background', '#333333');
document.documentElement.style.setProperty('--note-background', '#202020');
} else if (getTheme.theme === "Custom") {
} else if (getTheme && getTheme.theme === "Custom") {
document.documentElement.style.setProperty('--background', getTheme.themeColors.background);
document.documentElement.style.setProperty('--main-color', getTheme.themeColors.mainColor);
document.documentElement.style.setProperty('--main-color-darker', getTheme.themeColors.mainColorDarker);
Expand Down
110 changes: 91 additions & 19 deletions assets/js/ts_fas_acih.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const pathName = pageURL.pathname;
let isOnDesktopApp = null;

// TransSocial Version
let transsocialVersion = "v2024.10.7";
let transsocialUpdate = "v2024107-1";
let transsocialVersion = "v2024.10.14";
let transsocialUpdate = "v20241014-1";
let transsocialReleaseVersion = "pre-alpha";

const notices = document.getElementsByClassName("version-notice");
Expand Down Expand Up @@ -347,7 +347,7 @@ if (pathName !== "/suspended.html" || pathName !== "/suspended") {
suspensionRef.on("value", (snapshot) => {
const data = snapshot.val();

if (data.suspensionStatus === "suspended") {
if (data && data.suspensionStatus === "suspended") {
if (pathName !== "/suspended" && pathName !== "/suspended.html") {
window.location.replace("/suspended");
}
Expand Down Expand Up @@ -389,7 +389,9 @@ firebase.auth().onAuthStateChanged((user) => {
document.getElementById("notificationsCount").classList.add("show");
document.getElementById("notificationsCount").innerHTML = `${unreadNotifications}`;
} else {
document.getElementById("notificationsCount").classList.remove("show");
if (document.getElementById("notificationsCount")) {
document.getElementById("notificationsCount").classList.remove("show");
}
}
})
}
Expand All @@ -414,7 +416,9 @@ firebase.auth().onAuthStateChanged((user) => {
const hasDoneIt = snapshot.exists();

if (!hasDoneIt) {
document.getElementById("updatesBtn").innerHTML = `<i class="fa-solid fa-wrench"></i> Updates <span class="badge">New!</span>`;
if (document.getElementById("updatesBtn")) {
document.getElementById("updatesBtn").innerHTML = `<i class="fa-solid fa-wrench"></i> Updates <span class="badge">New!</span>`;
}
}
})
} else {
Expand Down Expand Up @@ -444,15 +448,39 @@ if (document.getElementById("404page")) {

// If user is on the register page and is not signed in, redirect to /
if (pathName === "/auth/register" || pathName === "/auth/register.html") {
const url = new URL(window.location.href);
const urlParam = url.searchParams.get("return_to");

if (urlParam && urlParam === "https://music.transs.social/") {
document.getElementById("redirectNotice").innerHTML = `<i class="fa-solid fa-triangle-exclamation"></i> You'll be returned to TransMusic after you create your account.`;
} else if (urlParam && urlParam !== "https://music.transs.social/") {
document.getElementById("redirectNotice").innerHTML = `<i class="fa-solid fa-triangle-exclamation"></i> You'll be returned to ${urlParam} after you create your account.`;
} else {
document.getElementById("redirectNotice").remove();
}

firebase.auth().onAuthStateChanged((user) => {
if (user) {
window.location.replace("/auth/policies");
if (!urlParam) {
window.location.replace("/auth/policies");
} else {
window.location.replace(`/auth/policies?return_to=${urlParam}`);
}
} else {
// no need to do anything
}
})
}

if (pathName === "/auth/policies") {
const url = new URL(window.location.href);
const urlParam = url.searchParams.get("return_to");

if (urlParam) {
document.getElementById("continueBtn").href = `/auth/pfp?return_to=${urlParam}`;
}
}

// If user is on /auth/pfp, make sure their email is saved
// We also add their profile picture here
if (pathName === "/auth/pfp") {
Expand All @@ -464,7 +492,14 @@ if (pathName === "/auth/pfp") {

firebase.database().ref(`users/${user.uid}/pfp`).once("value", (snapshot) => {
if (snapshot.exists()) {
window.location.replace("/auth/names");
const url = new URL(window.location.href);
const urlParam = url.searchParams.get("return_to");

if (!urlParam) {
window.location.replace("/auth/names");
} else {
window.location.replace(`/auth/names?return_to=${urlParam}`);
}
}
});
} else {
Expand Down Expand Up @@ -521,7 +556,14 @@ if (pathName === "/auth/pfp") {
pfp : file.name
})
.then(() => {
window.location.replace("/auth/names");
const url = new URL(window.location.href);
const urlParam = url.searchParams.get("return_to");

if (!urlParam) {
window.location.replace("/auth/names");
} else {
window.location.replace(`/auth/names?return_to=${urlParam}`);
}
});
})
}
Expand All @@ -537,7 +579,14 @@ if (pathName === "/auth/pfp") {
if (user) {
firebase.database().ref(`users/${user.uid}/username`).once("value", (snapshot) => {
if (snapshot.exists()) {
window.location.replace("/auth/done");
const url = new URL(window.location.href);
const urlParam = url.searchParams.get("return_to");

if (!urlParam) {
window.location.replace("/auth/done");
} else {
window.location.replace(`/auth/done?return_to=${urlParam}`);
}
}
});
} else {
Expand Down Expand Up @@ -598,7 +647,14 @@ function displayAndUsernameReserve() {
username : username
})
.then(() => {
window.location.replace("/auth/done");
const url = new URL(window.location.href);
const urlParam = url.searchParams.get("return_to");

if (!urlParam) {
window.location.replace("/auth/done");
} else {
window.location.replace(`/auth/done?return_to=${urlParam}`);
}
});
});
}
Expand All @@ -613,9 +669,14 @@ function displayAndUsernameReserve() {

// auth/done... not much to do, just check auth state
if (pathName === "/auth/done") {
const url = new URL(window.location.href);
const urlParam = url.searchParams.get("return_to");

firebase.auth().onAuthStateChanged((user) => {
if (user) {
// nothing to do
if (urlParam) {
window.location.replace(urlParam);
}
} else {
window.location.replace("/auth/register");
}
Expand All @@ -639,7 +700,14 @@ function register() {
firebase.database().ref(`users/${userCredential.uid}`).update({
email : email
}).then(() => {
window.location.replace("/auth/pfp");
const url = new URL(window.location.href);
const urlParam = url.searchParams.get("return_to");

if (urlParam) {
window.location.replace(`/auth/pfp?return_to=${urlParam}`);
} else {
window.location.replace("/auth/pfp");
}
});
})
.catch((error) => {
Expand Down Expand Up @@ -720,7 +788,9 @@ function validate_field(field) {
// Hide error by default
function hideErrorByDefault() {
const errorTxt = document.getElementById('errorTxt');
errorTxt.innerHTML = '';
if (errorTxt) {
errorTxt.innerHTML = '';
}
}

// Only allow user on page if they are signed in/signed out
Expand Down Expand Up @@ -2287,7 +2357,7 @@ function loadEverything() {
}

// TransSocial account stuff
if (pathName !== "/auth/login.html" && pathName !== "/auth/register.html" && pathName !== "/auth/katniny.html" && pathName !== "/auth/login" && pathName !== "/auth/register" && pathName !== "/auth/katniny") {
if (!pathName.startsWith("/auth/")) {
database.ref("users/G6GaJr8vPpeVdvenAntjOFYlbwr2").once("value", (snapshot) => {
const data = snapshot.val();
if (data !== null) {
Expand Down Expand Up @@ -7473,11 +7543,13 @@ if (pathName === "/search") {
}
}

document.getElementById("searchBar").addEventListener("keydown", (event) => {
if (event.key === "Enter") {
window.location.replace(`/search?q=${document.getElementById("searchBar").value}`);
}
});
if (document.getElementById("searchBar")) {
document.getElementById("searchBar").addEventListener("keydown", (event) => {
if (event.key === "Enter") {
window.location.replace(`/search?q=${document.getElementById("searchBar").value}`);
}
});
}

// init stripe & allow users to create a subscription
// also yes. this key is safe to have out. this wasn't an accident lol. (wait, you cant do that, it would violate our license)
Expand Down
2 changes: 1 addition & 1 deletion auth/policies.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2>Contact Us</h2>
<br />
</div>

<a href="/auth/pfp"><button>Continue</button></a>
<a href="/auth/pfp" id="continueBtn"><button>Continue</button></a>
</div>
</body>

Expand Down
2 changes: 2 additions & 0 deletions auth/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ <h3 id="loaderQuote" style="position: absolute; margin-top: 180px;">
<h1><i class="fa-solid fa-hand-holding-heart"></i> Join TransSocial</h1>
<p>Join a safe place for everyone! <a href="/auth/login" style="color: var(--main-color);">Already have an account?</a></p>

<div class="badge" id="redirectNotice"><i class="fa-solid fa-triangle-exclamation"></i> You'll be returned to {link} after you create your account.</div>

<input type="text" id="email" placeholder="Enter your email address" />
<input type="password" id="password" placeholder="Enter a secure password" />
<p id="errorTxt" style="color: var(--error-text);">empty</p>
Expand Down
9 changes: 9 additions & 0 deletions updates.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ <h1 id="selectedFilter" style="text-decoration: underline; margin-bottom: 5px;">
<div id="prealphaVersions">
<p>Trying to find older updates? You may be interested in the InDev tab, since TransSocial is no longer in InDev!</p>

<div class="update">
<h2>v2024.10.14_pre-alpha</h2>
<h3 style="color: var(--text-semi-transparent);">Released: October 14, 2024</h3>
<li>Started allowing redirection to other Katniny websites</li>
<li>Fixed not being able to progress past the policies page during registration</li>
</div>

<br />

<div class="update">
<h2>v2024.10.7_pre-alpha</h2>
<h3 style="color: var(--text-semi-transparent);">Released: October 7, 2024</h3>
Expand Down

0 comments on commit 28a7d2e

Please sign in to comment.