From 6dcf0d455b4cd27e80290a1d4f184fd3d18cb086 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?c=C4=83t=C4=83lin?=
Date: Thu, 19 Dec 2024 18:49:14 +0100
Subject: [PATCH] fix: fix logout flow which wasn't being triggered, remove
useless html code
---
src/huesoporro/api/routes/api.py | 2 +-
src/huesoporro/static/js/utils.js | 33 -------------
src/huesoporro/templates/index.html | 12 ++---
src/huesoporro/templates/login.html | 62 +------------------------
src/huesoporro/templates/logout.html | 13 ++++++
src/huesoporro/templates/sentences.html | 15 +++---
src/huesoporro/templates/tts.html | 7 +--
7 files changed, 30 insertions(+), 114 deletions(-)
create mode 100644 src/huesoporro/templates/logout.html
diff --git a/src/huesoporro/api/routes/api.py b/src/huesoporro/api/routes/api.py
index d427cde..9412598 100644
--- a/src/huesoporro/api/routes/api.py
+++ b/src/huesoporro/api/routes/api.py
@@ -19,7 +19,7 @@ class ManageBotDTO(BaseModel):
"/tts",
media_type=MediaType.HTML,
)
-async def get_tts_overlay() -> Template:
+async def get_tts_overlay(user: User) -> Template:
return Template(template_name="tts.html")
diff --git a/src/huesoporro/static/js/utils.js b/src/huesoporro/static/js/utils.js
index e014ab2..9bb1116 100644
--- a/src/huesoporro/static/js/utils.js
+++ b/src/huesoporro/static/js/utils.js
@@ -7,36 +7,3 @@ function getWebsocketProtocol() {
return "wss://";
}
}
-
-function addLogoutEvent() {
- const logoutButton = document.getElementById("logoutButton");
- logoutButton.addEventListener("click", () => {
- document.cookie = "twitchLoginData=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
- window.location.href = "/";
- });
-
-}
-
-function setCookie(name, value, days) {
- const date = new Date();
- date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
- const expires = `expires=${date.toUTCString()}`;
- document.cookie = `${name}=${value};${expires};path=/;SameSite=Strict`;
-}
-
-function getCookie(name) {
- const cookieName = `${name}=`;
- const decodedCookie = decodeURIComponent(document.cookie);
- const cookieArray = decodedCookie.split(';');
-
- for (let i = 0; i < cookieArray.length; i++) {
- let cookie = cookieArray[i];
- while (cookie.charAt(0) === ' ') {
- cookie = cookie.substring(1);
- }
- if (cookie.indexOf(cookieName) === 0) {
- return cookie.substring(cookieName.length, cookie.length);
- }
- }
- return null;
-}
diff --git a/src/huesoporro/templates/index.html b/src/huesoporro/templates/index.html
index bdf08ee..b17419f 100644
--- a/src/huesoporro/templates/index.html
+++ b/src/huesoporro/templates/index.html
@@ -5,12 +5,10 @@
@@ -178,7 +176,7 @@
})
const data = await response.json()
console.log(data);
- if (response.ok){
+ if (response.ok) {
alert("Settings saved successfully")
}
}
@@ -186,8 +184,6 @@
const chatbotManager = new ChatbotManager();
chatbotManager.setEvents();
-
- addLogoutEvent()
});
Huesoporro🦴🍃
@@ -20,14 +17,18 @@
- | Sentence |
+ Sentence |
Action |
{% for sentence in sentences %}
| {{ sentence.sentence }} |
- |
+
+
+ |
{% endfor %}
diff --git a/src/huesoporro/templates/tts.html b/src/huesoporro/templates/tts.html
index a0f3266..5a7843e 100644
--- a/src/huesoporro/templates/tts.html
+++ b/src/huesoporro/templates/tts.html
@@ -8,10 +8,7 @@
TTS
Le Funny
-
-
+ {% include 'logout.html' %}
Huesoporro🦴🍃
@@ -186,7 +183,7 @@
// generate /tts/permalink?access_token=
// the access token is available in the twitchLoginData cookie
- const cookie = JSON.parse(getCookie("twitchLoginData"))
+ const cookie = JSON.parse(getCookie("huesoporroAuth"))
const permalinkUrl = `${window.location.origin}/tts/permalink?access_token=${cookie.access_token}`;
navigator.clipboard.writeText(permalinkUrl);
alert('OBS link copied to clipboard ' + permalinkUrl);