fix: fix logout flow which wasn't being triggered, remove useless html code

This commit is contained in:
cătălin 2024-12-19 18:50:05 +01:00
commit 3186afe96d
No known key found for this signature in database
11 changed files with 34 additions and 118 deletions

View file

@ -21,4 +21,4 @@ version: 0.2.4
# incremented each time you make changes to the application. Versions are not expected to # incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using. # follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes. # It is recommended to use it with quotes.
appVersion: "0.2.4" appVersion: "0.2.5"

View file

@ -11,7 +11,7 @@ image:
# This sets the pull policy for images. # This sets the pull policy for images.
pullPolicy: Always pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion. # Overrides the image tag whose default is the chart appVersion.
tag: "0.2.4" tag: "0.2.5"
# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ # This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
imagePullSecrets: [] imagePullSecrets: []

View file

@ -1,6 +1,6 @@
[project] [project]
name = "huesoporro" name = "huesoporro"
version = "0.2.4" version = "0.2.5"
description = "Misc Twitch bots" description = "Misc Twitch bots"
readme = "README.md" readme = "README.md"
authors = [ authors = [

View file

@ -19,7 +19,7 @@ class ManageBotDTO(BaseModel):
"/tts", "/tts",
media_type=MediaType.HTML, media_type=MediaType.HTML,
) )
async def get_tts_overlay() -> Template: async def get_tts_overlay(user: User) -> Template:
return Template(template_name="tts.html") return Template(template_name="tts.html")

View file

@ -7,36 +7,3 @@ function getWebsocketProtocol() {
return "wss://"; 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;
}

View file

@ -5,12 +5,10 @@
<nav> <nav>
<ul> <ul>
<li>Chatbot</li> <li>Chatbot</li>
<li><a href="/tts">TTS</a></li> <li><a href="#" disabled>TTS</a></li>
<li><a href="/lefunny">Le Funny</a></li> <li><a href="#" disabled="true">Le Funny</a></li>
</ul>
<ul>
<li><a id="logoutButton" href="#" style="color: #aa0000;">Logout</a></li>
</ul> </ul>
{% include 'logout.html' %}
</nav> </nav>
</header> </header>
<main> <main>
@ -178,7 +176,7 @@
}) })
const data = await response.json() const data = await response.json()
console.log(data); console.log(data);
if (response.ok){ if (response.ok) {
alert("Settings saved successfully") alert("Settings saved successfully")
} }
} }
@ -186,8 +184,6 @@
const chatbotManager = new ChatbotManager(); const chatbotManager = new ChatbotManager();
chatbotManager.setEvents(); chatbotManager.setEvents();
addLogoutEvent()
}); });
</script> </script>
</body> </body>

View file

@ -6,7 +6,8 @@
<main> <main>
<section> <section>
<form> <form>
<a role="button" href="{{ twitch_login_url }}" id="loginButton" type="button" style="background-color: #B645CD; border-color: #B645CD">Login <a role="button" href="{{ twitch_login_url }}" id="loginButton" type="button"
style="background-color: #B645CD; border-color: #B645CD">Login
with with
Twitch Twitch
</a> </a>
@ -14,66 +15,7 @@
</section> </section>
</main> </main>
<script> <script>
document.addEventListener("DOMContentLoaded", () => {
class LoginManager {
constructor() {
this.loginData = null;
}
async readLoginData() {
const loginData = getCookie("twitchLoginData");
try {
this.loginData = loginData ? JSON.parse(loginData) : null;
return this.loginData;
} catch (error) {
console.error("Error reading login data:", error);
return null;
}
}
async saveSettings() {
// Check if access_token is present in the URL hash
const hashParams = new URLSearchParams(window.location.hash.substring(1));
const accessToken = hashParams.get('access_token');
if (accessToken) {
const loginData = {
access_token: accessToken,
timestamp: new Date().toISOString()
};
try {
setCookie("twitchLoginData", JSON.stringify(loginData), 30);
this.loginData = loginData;
const loginButton = document.getElementById("loginButton");
if (loginButton) {
loginButton.style.display = 'none';
}
history.replaceState(null, document.title, window.location.pathname);
window.location.href = '/';
} catch (error) {
console.error("Error saving login data:", error);
}
}
}
}
const loginManager = new LoginManager();
loginManager.readLoginData().then(loginData => {
const loginButton = document.getElementById("loginButton");
if (loginData) {
window.location.href = '/';
} else {
loginManager.saveSettings();
}
});
});
</script> </script>
</body> </body>

View file

@ -0,0 +1,13 @@
<ul>
<li><a id="logoutButton" href="#" style="color: #aa0000;">Logout</a></li>
</ul>
<script>
document.addEventListener("DOMContentLoaded", () => {
const logoutButton = document.getElementById("logoutButton");
logoutButton.addEventListener("click", () => {
console.log("Logging out...");
document.cookie = "huesoporroAuth=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
window.location.href = "/";
});
});
</script>

View file

@ -1,17 +1,14 @@
{% include 'header.html' %} {% include 'header.html' %}
<body> <body>
<header> <header>
<nav> <nav>
<ul> <ul>
<li><a href="/">Chatbot</a> </li> <li><a href="/">Chatbot</a></li>
<li><a href="/tts">TTS</a></li> <li><a href="/tts">TTS</a></li>
<li>Le Funny</li> <li>Le Funny</li>
</ul> </ul>
<ul> {% include 'logout.html' %}
<li><a id="logoutButton" href="#" style="color: #aa0000;">Logout</a></li>
</ul>
</nav> </nav>
<h1>Huesoporro🦴🍃</h1> <h1>Huesoporro🦴🍃</h1>
</header> </header>
@ -20,14 +17,18 @@
<table> <table>
<thead style="background-color: white; color: black"> <thead style="background-color: white; color: black">
<tr> <tr>
<th >Sentence</th> <th>Sentence</th>
<th>Action</th> <th>Action</th>
</tr> </tr>
</thead> </thead>
{% for sentence in sentences %} {% for sentence in sentences %}
<tr> <tr>
<td>{{ sentence.sentence }}</td> <td>{{ sentence.sentence }}</td>
<td><button id="delete-{{ sentence.id }}" style="border-color: #aa0000; background-color: #aa0000">Delete</button></td> <td>
<button id="delete-{{ sentence.id }}" style="border-color: #aa0000; background-color: #aa0000">
Delete
</button>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View file

@ -8,10 +8,7 @@
<li>TTS</li> <li>TTS</li>
<li><a href="/lefunny">Le Funny</a></li> <li><a href="/lefunny">Le Funny</a></li>
</ul> </ul>
<ul> {% include 'logout.html' %}
<li><a id="logoutButton" href="#" style="color: #aa0000;">Logout</a></li>
</ul>
</nav> </nav>
<h1>Huesoporro🦴🍃</h1> <h1>Huesoporro🦴🍃</h1>
</header> </header>
@ -186,7 +183,7 @@
// generate <ur>/tts/permalink?access_token=<access_token> // generate <ur>/tts/permalink?access_token=<access_token>
// the access token is available in the twitchLoginData cookie // 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}`; const permalinkUrl = `${window.location.origin}/tts/permalink?access_token=${cookie.access_token}`;
navigator.clipboard.writeText(permalinkUrl); navigator.clipboard.writeText(permalinkUrl);
alert('OBS link copied to clipboard ' + permalinkUrl); alert('OBS link copied to clipboard ' + permalinkUrl);

2
uv.lock generated
View file

@ -460,7 +460,7 @@ wheels = [
[[package]] [[package]]
name = "huesoporro" name = "huesoporro"
version = "0.2.4" version = "0.2.5"
source = { virtual = "." } source = { virtual = "." }
dependencies = [ dependencies = [
{ name = "aiosqlite" }, { name = "aiosqlite" },